Introduction to the

In daily work, Docker contacts a lot. In addition to the frequently used Docker run, docker stop and other commands, Docker also has a lot of very useful but not often used commands. Here I will summarize. Compiled a Java interview treasure book complete PDF

operation

1, the docker top

This command is used to view information about processes in a container, for example, if you want to see how many Nginx processes are in an nginx 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 processCopy the code

Docker load && Docker Save

I usually use these two commands to download the image of the packaged K8S, 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 that

Docker save registry: 2.7.1 > registry - 2.7.1. TarCopy the code

Docker load can also import images from tar files into docker

Docker load < 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 Nginx NAME DESCRIPTION STARS 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 privatebin/nginx-fpm-alpine privatebin Running on an nginx, php-fpm & Al... 31 [OK] Schmunk42 /nginx-redirect A Very simple container to redirect HTTP tra... 18 [OK] nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 16 nginx/nginx-prometheus-exporter NGINX Prometheus Centos/Nginx-112 -centos7 Platform for running Nginx 1.12 or building... 13 centos/nginx-18-centos7 Platform for running nginx 1.8 or building n... 13 Raulr /nginx-wordpress Nginx front-end for the Official wordpress: F... 13 [OK] My friend is a scrapes nginx VTS server. Scrapes nginx VTS server. 7 [OK] mailu/nginx Mailu nginx frontend 7 [OK] bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr... 6 [OK] Bitwarden/Nginx The Bitwarden Nginx Web Server acting as a R... 6 flashspys/nginx-static Super Lightweight Nginx Image 6 [OK] wodby/nginx Generic nginx 1 [OK] ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 1 [OK]Copy the code

Of course, this feature may not work particularly well in China

4, docker events

This command will help you to get information about various docker events in real time, such as creating a container, etc

➜  ~ docker events
2020-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 modification commands for each layer, or you want to see how an image is built, for example

➜ ~ 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 $(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 view the exit status of the container, for example

➜  ~ docker wait 7f7f0522a7d0
0
Copy the code

This will tell you if the container exits normally or abnormally

8, Docker pause && docker unpause

This command is used when you want to pause a container after running it

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 38c59255bf6e
C /etc
A /etc/localtime
C /var
C /var/lib
A /var/lib/registry
Copy the code

10 and 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. Compiled a Java interview treasure book complete PDF