Common command of docker operation – image

Time:2021-6-11

Get image

Docker pull [option] [docker registry address [: port number] /] warehouse name [: label]

Example:docker pull ubuntu:16.04

Specific options can be selected through thedocker pull --helpName see

Docker registry is docker hub by default, and the address format is < IP / domain name >
Example:docker pull ubuntu:16.04

Run container

Docker run warehouse name
Take the above Ubuntu as an example, if we want to start bash in it and do interactive operation

docker run -it --rm ubuntu:16.04 bash
  • -it: These are two parameters, one is-i: interactive operation, one is-tTerminal. We are going to enter bash to execute some commands and see the returned results, so we need an interactive terminal
  • --rm: this parameter will delete the container after exiting to avoid wasting space
  • ubuntu:16.04: start the container based on the image
  • bash: after the image is the command, here we want to have a switch shell\

To enter the running Ubuntu container and perform interactive operations:

docker exec -it [id] bash

usenginxThe image starts a container namedwebserver, mapped to port 80

docker run --name webserver -d -p 80:80 nginx

Modify container content

docker exec -it webserver bash
[email protected]:/# echo '<h1>Hello,world</h1>' > /usr/share/nginx/html/index.html
[email protected]:/# exit

At this point, we modify the storage layer of the container. You candocker diffSee the specific changes
adoptdocker commitYou can save the container as a mirror (but this is not recommended)
Docker commit [option] < container ID or container name > [< warehouse name > [: < label >]]

List images

docker image ls
  • List illusory imagesdocker image ls -f dangling=true
  • Delete a dangling imagedocker image prune
  • Lists all images including the middle tier imagesdocker image ls -a

Mirror volume

docker system df

List partial images

  • According to warehouse namedocker image ls ubuntu
  • List items by time

docker image ls -f since=ubuntu
docker image ls -f before=ubuntu

Display in a specific format

docker image ls --format "{{.ID}}:{{.Repository}}"
Equidistant display
docker image ls --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}"

Delete local mirror

Docker image RM [options] < image 1 > [< image 2 >...]

Among them,< mirror >It could beImage IDImage nameorImage summary

Using docker image LS command

Delete all warehouses namedhello-worldImage of:

docker image rm (docker image ls -q hello-world)

Delete all images before Ubuntu

docker image rm (docker image ls -q -f before=ubuntu)