Docker 的实验(第11个:镜像调查)
第十节:容器层的延续。
调查图像的方法
$ docker image inspect <image name>
如果想要在图像中查询特定事项,应该怎么做呢?
简单地使用grep搜索即可。
$ docker image inspect nginx | grep 'Hostname'
"Hostname": "412e505a8437",
"Hostname": "",
使用format选项。
$ docker image inspect nginx --format='{{.Id}}'
sha256:3f8a00f137a0d2c8a2163a09901e28e2471999fde4efc2f9570b91f1c30acf94
$ docker image inspect nginx --format='{{.ContainerConfig}}'
{412e505a8437 false false false map[80/tcp:{}] false false false [PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin NGINX_VERSION=1.23.3 NJS_VERSION=0.7.9 PKG_RELEASE=1~bullseye] [/bin/sh -c #(nop) CMD ["nginx" "-g" "daemon off;"]] <nil> false sha256:81125abfc1520356faf20748ab85157762879efb86ee42f5061fb58c7b5bbae3 map[] [/docker-entrypoint.sh] false [] map[maintainer:NGINX Docker Maintainers <docker-maint@nginx.com>] SIGQUIT <nil> []}
以 JSON 格式显示。
$ docker image inspect nginx --format='{{json .ContainerConfig}}'
{"Hostname":"412e505a8437","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"ExposedPorts":{"80/tcp":{}},"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","NGINX_VERSION=1.23.3","NJS_VERSION=0.7.9","PKG_RELEASE=1~bullseye"],"Cmd":["/bin/sh","-c","#(nop) ","CMD [\"nginx\" \"-g\" \"daemon off;\"]"],"Image":"sha256:81125abfc1520356faf20748ab85157762879efb86ee42f5061fb58c7b5bbae3","Volumes":null,"WorkingDir":"","Entrypoint":["/docker-entrypoint.sh"],"OnBuild":null,"Labels":{"maintainer":"NGINX Docker Maintainers <docker-maint@nginx.com>"},"StopSignal":"SIGQUIT"}
显示特定项目。
$ docker image inspect nginx --format='{{.ContainerConfig.Hostname}}'
412e505a8437
第12部分:紧随图像清理和搜索之后。