简介
在平时的工作中,docker接触很多,除了经常使用的docker run ,docker stop等命令,docker还有很多十分有用但是却不经常使用的命令,下面我就总结一下
操作
- docker top
这个命令是用来查看一个容器里面的进程信息的,比如你想查看一个nginx容器里面有几个nginx进程的时候,就可以这么做
➜ ~ 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
- docker load && docker save
我一般使用这两个命令去下载打包k8s的镜像,因为你知道的中国的网速并不像国外那么快
docker save可以把一个镜像保存到tar文件中,你可以这么做
docker save registry:2.7.1 >registry-2.7.1.tar
同时docker load可以把镜像从tar文件导入到docker中
docker load < registry-2.7.1.tar
- docker search
这个命令可以帮助你在命令行中方便的搜索dockerhub中的镜像,比如
➜ ~ 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]
当然这个功能在中国可能不会特别好用
- docker events
这个命令可以帮助你实时获取docker的各种事件信息,比如创建了一个容器什么的
➜ ~ docker events
2020-07-28T21:28:46.000403018+08:00 image load sha256:432bf69f0427b52cad10897342eaf23521b7d973566354118e9a59c4d31b5fae (name=sha256:432bf69f0427b52cad10897342eaf23521b7d973566354118e9a59c4d31b5fae)
- docker update
当你docker run 了之后却发现里面有一些参数并不是你想要的状态比如你设置的nginx容器cpu或者内存太小,这个时候你就可以使用docker update去修改这些参数
docker update nginx --cpus 2
- 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… 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
这个命令可以查看容器的退出状态,比如
➜ ~ docker wait 7f7f0522a7d0
0
这样你就可以知道这个容器是正常退出的还是异常退出的了
- docker pause && docker unpause
当你运行了一个容器但是想要暂停它运行的时候可以使用这个命令
- docker diff
当你运行了一个容器,但是你不知道容器里修改了哪一些文件的时候可以使用这个命令,比如
➜ ~ docker diff 38c59255bf6e
C /etc
A /etc/localtime
C /var
C /var/lib
A /var/lib/registry
- docker stats
这个是docker内置的监控命令,当你想要查看当前主机下所有容器占用内存和cpu的情况的时候就可以使用这个命令
欢迎关注我的博客www.bboy.app
Have Fun