Detailed description of dock command

install Just install ce (community version)

Start command

Start docker

systemctl start docker

Close docker

systemctl stop docker

Restart docker

systemctl restart docker

docker settings start automatically when the service starts

systemctl enable docker

View Status

View docker Running Status

systemctl status docker

View Version

docker version

View Details

docker info

Mirror related

Check the installed images of the local environment

#-a means display all, - q means display ID only
docker images -a

Querying the Dockcer Warehouse (docker hub) Image

Official warehouse of dokcer:

docker search mysql

Upload the image to the docker hub

#Upload image:
docker push hello:V1

Pull warehouse image to local

Pull the latest version in the docker warehouse without tag (version number)

#The latest version of the image plus: tag pulls the specified version
docker pull hello-world

delete mirror

#Delete a single mirror
docker rmi hello-world(Image name/image ID)
#Force (- f) to delete multiple image ID s or separate images with spaces 
docker rmi -f Image name/image ID Image name/image ID Image name/image ID
#Delete all images - a means display all, - q means display only ID s
docker rmi -f $(docker images -aq)

Save the image as a local file

#docker save -o Image save location and name Image name/image ID corresponds to docker load
docker save -o hello.tar hello-world

Load local files and restore them to images

#docker load -i The local file corresponds to the docker save
docker load -i hello.tar

Container related

The so-called container is the running version of the image, which is an isolated running system

Run Container

#docker run image name [version]/image ID
docker run hello-world

The run command in docker is very complex. What are the persistent running mapping ports, container aliases, data volume mounts, etc

Only a few common parameters are introduced here

  -d, --detach                         Run the container in the background and return to the container ID
  -e, --env list                       Set container environment variables
  -i, --interactive                    Run the container in interactive mode, usually with -t Simultaneous use
  -m, --memory bytes                   Maximum container memory
      --name string                    Specify container name
  -p, --publish list                   Specify port mapping host port:Container Port
  -t, --tty                            Reassign a pseudo input terminal for the container, usually with -i Simultaneous use
  -v, --volume list                    Attach the data volume to the container
  -w, --workdir string                 assign work directory

give an example:

docker run -dit \
  -v $PWD/ql/config:/ql/config \
  -p 5600:5600 \
  --name qinglong \
  --hostname qinglong \
  --restart unless-stopped \

Start the redis container and check whether the exposed port is successful in the win environment (remember to release the cloud environment port interception)

docker run --name redis -p 6379:6379 -d redis:6.0

Testing the link to redis:

View Container

#View Running Container
docker ps
#View all containers, including stopped
docker ps -a

Stop Container

#docker stop container name/container ID
docker stop redis
docker stop 8ddadf5d2ff3

Delete Container

Stop before deleting

#dokcer rm container name/container ID
docker rm redis

Import Export Container

#docker export -o Save path and file name Container name/container ID
docker export -o redis.tar redis
#docker import file image name [: tag] docker import imports a container into an image instead of restoring it to a container.
docker import redis.tar redis:dev

This command is similar to the previous image of docker save. The main differences are as follows:

  • docker export needs to specify a container. You cannot specify either an image or a container as docker save does.
  • docker save saves image s, and docker export saves container s;
  • docker load is used to load the image package, and docker import is used to load the container package, but both will be restored as images;
  • docker load cannot rename the loaded image. docker import can specify a new name for the image.
  • The application scenario of docker save is that if your application uses docker compose A combination of multiple images arranged by yml, but the client server you want to deploy cannot connect to the internet. At this time, you can use Docker Save to package the images used, and then copy them to the client server for loading using docker load.
  • The docker export application scenario is mainly used to create a basic image. For example, you can start a container from a ubuntu image, install some software and make some settings, and then use docker export to save it as a basic image. Then, distribute the image to others for use, such as the basic development environment.

Enter the running container

#docker exec -it container name/container ID sh
#Enter the redis container
docker exec -it redis sh

Or when starting the container, run it directly in interactive mode

docker run -it --name redis-dev redis:dev sh

Or use docker attach container name/container ID (not commonly used)

Exit after entering the container:

#Exit directly --- The container for executing this parameter will be closed when - d (background running) is not added  
# Graceful exit --- The container will not be closed when executing this command regardless of whether the - d parameter is added or not
Ctrl + p + q

Restart container

#docker restart container ID/container name
dokcer restart redis

Operation and maintenance related

View the memory occupied by the container

#docker stats container name/container ID
dokcer stats redis

View the disk occupied by docker

docker system df

View container run log

#docker logs container name/container ID
docker logs redis

View container operation information

#docker inspect container ID/name
docker inspect redis

Copy file to container

#docker cp container ID/name: the path to copy the file to the outside 
docker cp container ID/name: Inside container path Outside container path
#Copy files from the outside to the container
docker cp Out of container path container ID/name: In container path

Replace container name

docker rename container ID/Container Name New Container Name

Update container parameters

If you do not want to delete the container and want to set the container to boot automatically, you can modify its boot configuration!

docker update --restart=always container Id/Container name


A picture found on the Internet is very clear:

reference resources:

Tags: Linux Docker Container

Posted by wata on Sun, 18 Sep 2022 21:43:12 +0300