In addition to basic Docker pull , Docker Image , Docker PS , there are some commands and parameters are also very important in this record down to avoid forgetting.
Environmental Information
The following is the environment of this operation:
- Operating System: CentOS Linux release 7.7.1908
- Docker:19.03.2
Suppose the current environment is running two containers, the following operations are carried out based on these two containers:
[root@vostro harbor]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
11548ac31116 tomcat:9.0.26-jdk8-openjdk "catalina.sh run" 6 seconds ago Up 5 seconds 8080/tcp inspiring_ardinghelli
21c0499ccc76 nginx "nginx -g 'daemon of…" 29 minutes ago Up 29 minutes 80/tcp strange_zhukovsky
General Information
docker info used to view the whole message:
[root@vostro harbor]# docker info
Client:
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 19
Server Version: 19.03.2
Storage Driver: overlay
Backing Filesystem: xfs
Supports d_type: true
...
Free up space
- docker system prune deletes the following:
. A container has been stopped;
. B unused network;
. C all no label image;
. d cache generated when building the mirror;
Note: too much of this command to delete something, so be careful
- Delete the container has stopped: Docker Container Prune
- Delete unused network: Docker Network Prune
- Tag does not delete the image: Docker Image Prune
- Deletion is not mirrored container: Docker Image Prune -a
Delete unused data volumes: Docker Volume Prune
filter
Execution docker ps when the vessel lists all operating conditions, sometimes we just want to see their concerns, then you can do filter results:- Filter press container ID: Docker ID = -f PS 11548ac31116
[root@vostro harbor]# docker ps -f id=11548ac31116
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
11548ac31116 tomcat:9.0.26-jdk8-openjdk "catalina.sh run" 4 minutes ago Up 4 minutes 8080/tcp inspiring_ardinghelli
- Filter by container name: Docker PS name = -f inspiring_ardinghelli
[root@vostro harbor]# docker ps -f name=inspiring_ardinghelli
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
11548ac31116 tomcat:9.0.26-jdk8-openjdk "catalina.sh run" 7 minutes ago Up 7 minutes 8080/tcp inspiring_ardinghelli
- Mirror image filtering, such filtering subdivided in three ways:
. a filter press image name and the TAG: Docker PS = -f ancestor Tomcat: 9.0.26-jdk8-OpenJDK
. b Filter mirror image ID: Docker PS = -f ancestor 4965bfab1881
. c in accordance with the image information filtering Summary: Docker PS -f ancestor Tomcat @ = sha256: 67a9904e3ceb03abc50db7b374db7362f7e44d08a41488dd24c2bb14df8989a3
how to obtain summary information mirroring it? Run docker inspect tomcat: 9.0.26-jdk8- openjdk can get details of the mirror, as shown below, the red box that FIG summary information:
- Filter container according to the state: Docker PS -f Status = running , these states are: created, restarting, running, removing , paused, exited, dead
- There are other filters, to but not used, as shown below:
Access to information
- Check disk space occupied by the container: Docker PS -s
on the map the red box is a container resource consumption, 508MB said: image size + size of the container itself, 40KB represents a container the size of their share of resources; - Look some fields when the container to view information, such as the container ID look, mirror, these three container name: Docker --format PS "Table .ID {{}}: {{}} .image: {} {.Names } "
[root@vostro harbor]# docker ps --format "table {{.ID}}: {{.Image}}: {{.Names}}"
CONTAINER ID: IMAGE: NAMES
11548ac31116: tomcat:9.0.26-jdk8-openjdk: inspiring_ardinghelli
21c0499ccc76: nginx: strange_zhukovsky
The following figure shows all of the name of the column:
- As shown in FIG red box, when the field is too long, a part of the display, if you want to view complete information using the docker ps --no-trunc
In use docker history command to view the image information constructed will be omitted because the content is too long, as shown, it can also be used at this time --no-trunc parameter information is omitted, see:
Combination
- Show only Tomcat container ID field: Docker PS = -f ancestor Tomcat: 9.0.26-jdk8-OpenJDK -q
[root@vostro harbor]# docker ps -f ancestor=tomcat:9.0.26-jdk8-openjdk -q
11548ac31116
- The above command can be Tomcat container ID field, if we want to stop the container, and the above-described command docker stop combination used to: docker stop $ (-f ancestor Docker PS = Tomcat: 9.0.26-jdk8-OpenJDK - q)
[root@vostro harbor]# docker stop $(docker ps -f ancestor=tomcat:9.0.26-jdk8-openjdk -q)
11548ac31116
[root@vostro harbor]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
11548ac31116 tomcat:9.0.26-jdk8-openjdk "catalina.sh run" About an hour ago Exited (143) 43 seconds ago inspiring_ardinghelli
21c0499ccc76 nginx "nginx -g 'daemon of…" 2 hours ago Up 2 hours 80/tcp strange_zhukovsky
Visible tomcat container has stopped.
These are my daily work docker frequently used commands. For more information, please refer to the official document: https: //docs.docker.com/engine/reference/commandline/docker/