Docker commonly used commands a small note

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:

  1. Operating System: CentOS Linux release 7.7.1908
  2. 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

  1. 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

  1. Delete the container has stopped: Docker Container Prune
  2. Delete unused network: Docker Network Prune
  3. Tag does not delete the image: Docker Image Prune
  4. Deletion is not mirrored container: Docker Image Prune -a
  5. 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:
  6. 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
  1. 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
  1. 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:
Here Insert Picture Description

  1. Filter container according to the state: Docker PS -f Status = running , these states are: created, restarting, running, removing , paused, exited, dead
  2. There are other filters, to but not used, as shown below:
    Here Insert Picture Description

Access to information

  1. Check disk space occupied by the container: Docker PS -s
    Here Insert Picture Description
    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;
  2. 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:
Here Insert Picture Description

  1. 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
    Here Insert Picture Description
  2. 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:
    Here Insert Picture Description

    Combination

  3. 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
  1. 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/

I welcome the attention of the public numbers: programmer Chen Xin

Guess you like

Origin www.cnblogs.com/bolingcavalry/p/11570047.html