在平時的工做中,docker接觸不少,除了常常使用的docker run ,docker stop等命令,docker還有不少十分有用可是卻不常常使用的命令,下面我就總結一下。php
這個命令是用來查看一個容器裏面的進程信息的,好比你想查看一個nginx容器裏面有幾個nginx進程的時候,就能夠這麼作linux
➜ ~ 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複製代碼
我通常使用這兩個命令去下載打包k8s的鏡像,由於你知道的中國的網速並不像國外那麼快nginx
docker save能夠把一個鏡像保存到tar文件中,你能夠這麼作web
docker save registry:2.7.1 >registry-2.7.1.tar複製代碼
同時docker load能夠把鏡像從tar文件導入到docker中docker
docker load < registry-2.7.1.tar複製代碼
這個命令能夠幫助你在命令行中方便的搜索dockerhub中的鏡像,好比centos
➜ ~ docker search nginx NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx. 13519 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1846 [OK] richarvey/nginx-php-fpm Container 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… 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 Exporter 14 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] sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a… 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]複製代碼
固然這個功能在中國可能不會特別好用frontend
這個命令能夠幫助你實時獲取docker的各類事件信息,好比建立了一個容器什麼的ide
➜ ~ docker events 2020-07-28T21:28:46.000403018+08:00 image load sha256:432bf69f0427b52cad10897342eaf23521b7d973566354118e9a59c4d31b5fae (name=sha256:432bf69f0427b52cad10897342eaf23521b7d973566354118e9a59c4d31b5fae)複製代碼
當你docker run 了以後卻發現裏面有一些參數並非你想要的狀態好比你設置的nginx容器cpu或者內存過小,這個時候你就可使用docker update去修改這些參數wordpress
docker update nginx --cpus 2複製代碼
當你修改了一個鏡像,可是忘記了每一層的修改命令,或者你想查看一個鏡像是怎麼構建的時候就可使用這個命令,好比php-fpm
➜ ~ 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… 419B <missing> 5 months ago /bin/sh -c set -ex; apkArch="$(apk --print-… 52.9MB <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.81MB複製代碼
這個命令能夠查看容器的退出狀態,好比
➜ ~ docker wait 7f7f0522a7d0 0複製代碼
這樣你就能夠知道這個容器是正常退出的仍是異常退出的了
當你運行了一個容器可是想要暫停它運行的時候可使用這個命令
當你運行了一個容器,可是你不知道容器裏修改了哪一些文件的時候可使用這個命令,好比
➜ ~ docker diff 38c59255bf6e C /etc A /etc/localtime C /var C /var/lib A /var/lib/registry複製代碼
這個是docker內置的監控命令,當你想要查看當前主機下全部容器佔用內存和cpu的狀況的時候就可使用這個命令。