Docker command combing

What is Docker?

lightweight virtual machine

Docker common commands

Start: systemctl start docker
Stop: systemctl stop docker
Restart: systemctl restart docker
View docker status: systemctl status docker
Startup: systemctl enable docker
View docker overview information: docker info
View docker overall help documentation: docker --help
View docker command help documentation : docker specific command --help

Mirroring related:
docker images list the mirrors on the local host
-a list all local mirrors
-q only display the mirror ID
docker search a xxx mirror name (find a certain mirror name, if there is no local mirror, go to the hub to find it)
–limit n mirror name Limit the output of n images
(–limit is the default output of 25)
docker pull a certain xxx image name (download image)
docker pull image name [: TAG] (TAG is the image version)
docker pull image name without TAG will default to the latest version
, etc. Priced at
docker pull image name: latest
docker pull ubuntu

docker system df View the space occupied by images/containers/data volumes

docker rmi a xxx image name ID to delete a single
image : docker rmi -f image ID to delete multiple docker rmi -f image name 1: TAG image name 2: TAG delete all: docker rmi -f $(docker images -qa)



Dummy mirror:
REPOSITORY and TAG are both

Container related:

New+Start container:
docker run [OPTIONS] IMAGE [COMMAND] [ARG…]
OPTIONS:
–name=“new name for container” Specify a name for the container;
-d: Run the container in the background and return the container ID, that is, start the daemon Containers (running in the background)

-i:以交互模式运行容器,通常与-t同时使用;
-t:为容器重新分配一个伪输入终端,通常与-i 同时使用;

That is: start an interactive container (there is a pseudo-terminal in the foreground, waiting for interaction);

-P: 随机端口映射,大写P
-p:指定端口映射,小写p

Start the interactive container: ie: the foreground command line

List all currently running containers:
docker ps [OPTIONS]
[OPTIONS]: -a list all running or ever running containers
-l show recently created containers
-n show recently created n containers
-q silent mode , only the container ID is displayed

Two ways to launch the container:
exit: after run enters the container, exit exits, the container will stop
ctrl+p+q: run enters the container, ctrl+p+q exits, the container does not stop

Start a stopped container:
docker start container ID or container name

Restart the container:
docker restart container ID or container name

Stop the container:
docker stop container ID or container name

Force stop container:
docker kill container ID or container name

Delete a stopped container:
docker rm container ID

Delete multiple container instances at once
docker rm -f $(docker ps -a -q) Forcefully delete running containers
docker ps -a -q | xargs docker rm

guarded container

View container logs:
docker logs container ID

View the process running in the container:
docker top container ID

View the internal details of the container:
docker inspect container ID

Enter the interactive terminal without exiting:

docker exec -it containerid bashShell

Re-enter docker attach container ID

The difference between exec and attach:
attach directly enters the terminal of the container startup command, and will not start a new process. Exiting with exit will cause the container to stop.

exec is to open a new terminal in the container, and can start a new process and exit with exit without causing the container to stop.

To be added later

Guess you like

Origin blog.csdn.net/weixin_42529594/article/details/125150378