In daily work, Docker is in contact with a lot of, in addition to the often used Docker run, docker stop and other commands, Docker has a lot of very useful but not often used commands, the following is to summarize:
1. docker top
This command is used to view the process information in a container. For example, if you want to view the number of nginx processes in an nginx container, you can do this:
docker top 3b307a09d20dUID PID PPID C STIME TTY TIME CMDroot 805 787 0 Jul13 ? 00:00:00 nginx: master process nginx -g daemon off; systemd+ 941 805 0 Jul13 ? 00:03:18 nginx: worker processCopy the code
2. docker load && docker save
I usually use these two commands to download the image package of Kubernetes, because you know the Internet speed in China is not as fast as abroad.
Docker Save saves an image to a tar file. You can do this:
~ docker save registry:2.7.1 > registrie-2.7.1. Tar# Registry - 2.7.1. TarCopy the code
3. docker search
This command helps you easily search for images in DockerHub from the command line. For example:
~ docker search nginxNAME DESCRIPTION STARS OFFICIAL AUTOMATEDnginx Official build of Nginx. 13519 [OK] Jwilder /nginx-proxy Automated Nginx Proxy for Docker Con... 1846 [OK]richarvey/ nginx-fpm capable of running nginx + php-fpm capable of... 780 [OK] LinuxServer /nginx An nginx container, brought to you by LinuxS... 123 Bitnami/nginx Bitnami nginx Docker Image 87 [OK] tiangolo/nginx - RTMP Docker Image with nginx using the nginx - RTMP... 85 [OK]jc21/ nginx-proxy-Manager Docker container for managing nginx proxy ho... 73alfg/nginx-rtmp nginx, nginx-rtmp-module and FFmpeg from sou... 71 [OK] Nginxdemos/Hello NGINX webServer that serves a simple page co... 57 [OK]jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 53 [OK]nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 37......Copy the code
Of course, this function may not be particularly useful in China, because……
4. docker events
This command will help you get real-time information about various docker events, such as the creation of a container.
~ Docker Events2020-07-28T21:28:46.000403018 +08:00 image Load sha256:432bf69f0427b52cad10897342eaf23521b7d973566354118e9a59c4d31b5fae (name=sha256:432bf69f0427b52cad10897342eaf23521b7d973566354118e9a59c4d31b5fae)Copy the code
5. docker update
When you run a docker and find that some parameters are not in the desired state, such as the CPU or memory of the nginx container is too small, you can use docker Update to modify these parameters.
~ docker update nginx --cpus 2
Copy the code
6. docker history
You can use this command when you modify an image but forget the commands for each layer, or you want to see how an image is built, for example:
~ docker history Traefik :v2.1.6IMAGE CREATED CREATED BY SIZE COMMENT5212a87ddaba 5 months ago /bin/sh c #(noP) LABEL Org. Opencontainers.... 0B<missing> 5 months ago /bin/sh -c #(nop) CMD ["traefik"] 0B<missing> 5 months ago /bin/sh -c #(nop) ENTRYPOINT ["/entrypoint.... 0B<missing> 5 months ago /bin/sh -c #(nop) EXPOSE 80 0B<missing> 5 months ago /bin/sh -c #(nop) COPY $(print-) $(print-) $(print-) $(print-) $(print-) $(print-) 529 MB<missing> 5 months ago /bin/sh -c apk --no-cache add ca-certificate... 1.85MB<missing> 6 months ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B<missing> 6 months ago /bin/sh -c #(nop) ADD File: a1906f14a4e217a49... 4.81 MBCopy the code
7. docker wait
This command can check the exit status of the container, for example:
~ docker wait 7f7f0522a7d00
Copy the code
This will tell you if the container exits normally or abnormally.
8. docker pause && docker unpause
You can use this command when you want to suspend a container after running it.
~ docker pause 7f7f0522a7d0
Copy the code
9. docker diff
You can use this command when you run a container and you don’t know which files have been modified in the container, for example:
~ docker diff 38c59255bf6eC /etcA /etc/localtimeC /varC /var/libA /var/lib/registry
Copy the code
10. docker stats
This is a built-in docker monitoring command that you can use when you want to check the memory and CPU usage of all containers on the current host.
~ docker statsCONTAINER ID NAME CPU % MEM USAGE/LIMIT MEM % NET I/O BLOCK I/O PIDS1c5ade04e7f9 redis 0.08% 17.53MiB / 47.01GiB 0.04% 10.9GB / 37GB 0B / 0B 4AFe6D4EBE409 Kafka - half 0.09% 16.91MiB / 47.01GiB 0.04% 1.97GB / 1.53GB 752MB / 0B 23f0c7c01a9c34 kafka-docker_zookeeper 0.01% 308.8MiB / 47.01GiB 0.64% 20.2MB / 12.2MB 971MB / 3.29MB 28da8c5008955f Kafka-docker_kafka-manager 0.08% 393.2MiB / 47.01GiB 0.82% 1.56MB / 2.61MB 1.14GB / 0B 60C8D51C583C49 Kafka -docker_kafka 1.63% 1.256GiB / 47.01GiB 2.67% 30.4GB / 48.9GB 22.3GB / 5.77GB 85......Copy the code
Source: suo. Im / 6 n2lla