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. The docker top command is used to view the process information in a container, for example, you want to view the number of nginx processes in a container:

docker top 3b307a09d20d
UID      PID    PPID    C    STIME  TTY    TIME       CMD
root     805    787     0    Jul13   ?   00:00:00  nginx: master process nginx -g daemon off;
systemd+ 941     805     0   Jul13    ?   00:03:18  nginx: worker process
Copy the code

I usually use these two commands to download and pack Kubernetes images, because you know the Internet speed in China is not as fast as in foreign countries.

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

Docker search is a command that allows you to easily search for images in DockerHub. For example:

~ docker search nginx NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx 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 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... 73 alfg/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……

Docker events this command can help you to get information about docker events in real time, such as creating a container.

~ docker events
2020-07-28T21:28:46.000403018+08:00 image load sha256:432bf69f0427b52cad10897342eaf23521b7d973566354118e9a59c4d31b5fae (name=sha256:432bf69f0427b52cad10897342eaf23521b7d973566354118e9a59c4d31b5fae)
Copy the code

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 the Docker update to modify these parameters.

~ docker update nginx --cpus 2

Docker history docker history docker history docker history docker history docker history docker history docker history docker history docker history docker history docker history docker history docker history docker history

~ docker history Traefik :v2.1.6 IMAGE CREATED CREATED BY SIZE COMMENT 5212a87DDaba 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 File :59a219a1fb7a9dc8 <missing> 5 months ago /bin/sh -c set-ex; apkArch="$(apk --print-... 529MB <missing> 5 months ago /bin/sh -c set-ex 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:a1906f14a4e217a49Copy the code

7. Docker wait to check the container exit status, for example:

~ docker wait 7f7f0522a7d0
0
Copy the code

This will tell you if the container exits normally or abnormally.

Docker unpause this command is used when you want to pause a container after running it.

~ docker pause 7f7f0522a7d0

Docker diff docker diff docker diff docker diff docker diff docker diff docker diff

~ docker diff 38c59255bf6e
C /etc
A /etc/localtime
C /var
C /var/lib
A /var/lib/registry
Copy the code

Docker stats – Docker stats – docker stats – docker stats – Docker stats – Docker stats – Docker stats

~ Docker stats CONTAINER ID NAME CPU % MEM USAGE/LIMIT MEM % NET I/O BLOCK I/O PIDS 1C5ADE04E7f9 Redis 0.08% 17.53MiB / 47.01GiB 0.04% 10.9GB / 37GB 0B / 0B 4 AFE6D4EBE409 Kafka - half 0.09% 16.91MiB / 47.01GiB 0.04% 1.97GB / 1.53GB 752MB / 0B 23 f0C7C01a9c34 Kafka-docker_zookeeper 0.01% 308.8MiB / 47.01GiB 0.64% 20.2MB / 12.2MB 971MB / 3.29MB 28 Da8c5008955f kafka-docker_kafka-manager 0.08% 393.2MiB / 47.01GiB 0.82% 1.56MB / 2.61MB 1.14GB / 0B 60 c8D51C583C49 Kafka -docker_kafka 1.63% 1.256GiB / 47.01GiB 2.67% 30.4GB / 48.9GB 22.3GB / 5.77GB 85......Copy the code