我有一个泊坞窗映像,我想找出它是从哪个映像创建的。当然有多层,但是我想找出最后一张图像(dockerfile中该图像的FROM语句)?
我尝试使用docker image history,docker image inspect但无法在其中找到此信息。
docker image history
docker image inspect
我尝试使用以下命令,但它给我一条错误消息
alias dfimage="sudo docker run -v /var/run/docker.sock:/var/run/docker.sock --rm xyz/mm:9e945ff" dfimage febae8978318
这是我收到的错误消息
container_linux.go:235: starting container process caused "exec: \"febae8978318\": executable file not found in $PATH" /usr/bin/docker-current: Error response from daemon: oci runtime error: container_linux.go:235: starting container process caused "exec: \"febae8978318\": executable file not found in $PATH".
您可以使用此答案中建议的方法:https : //stackoverflow.com/a/53841690/3691891
首先,拉chenzj/dfimage:
chenzj/dfimage
docker pull chenzj/dfimage
获取图像的ID:
docker images | grep <IMAGE_NAME> | awk '{print $3}'
替换<IMAGE_NAME>为图像名称。使用此ID作为参数chenzj/dfimage:
<IMAGE_NAME>
docker run -v /var/run/docker.sock:/var/run/docker.sock --rm chenzj/dfimage <IMAGE_ID>
如果您觉得这太难了,请拉chenzj/dfimage图像,然后使用以下docker-get-dockerfile.sh脚本:
docker-get-dockerfile.sh
#!/usr/bin/env sh if [ "$#" -lt 1 ] then printf "Image name needed\n" >&2 exit 1 fi image_id="$(docker images | grep "^$1 " | awk '{print $3}')" if [ -z "$image_id" ] then printf "Image not found\n" >&2 exit 2 fi docker run -v /var/run/docker.sock:/var/run/docker.sock --rm chenzj/dfimage "$image_id"
您需要传递图像名称作为参数。用法示例:
$ ./docker-get-dockerfile.sh alpine FROM alpine:latest ADD file:fe64057fbb83dccb960efabbf1cd8777920ef279a7fa8dbca0a8801c651bdf7c in / CMD ["/bin/sh"]