如何找出Docker映像的基本映像 [英] How to find out the base image for a docker image
问题描述
我有一个docker映像,我想找出它是从哪个映像创建的。当然有多层,但我想找出最后一张图片(此图片在dockerfile中的FROM语句)?
I have a docker image and I would like to find out from which image it has been created. Of course there are multiple layers, but I'd like to find out the last image (the FROM statement in the dockerfile for this image)?
我尝试使用 docker镜像历史记录
和 docker镜像检查
但我在那里找不到此信息。
I try to use docker image history
and docker image inspect
but I can't find this information in there.
我尝试使用以下命令,但它给我一条错误消息
I tried to use the following command but it gives me a error message
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
You can use method suggested in this answer: https://stackoverflow.com/a/53841690/3691891
首先,拉 chenzj / dfimage
:
docker pull chenzj/dfimage
获取图像ID:
docker images | grep <IMAGE_NAME> | awk '{print $3}'
替换< IMAGE_NAME>
,并附上您的图片名称。使用此ID作为
参数,以 chenzj / dfimage
:
Replace <IMAGE_NAME>
with the name of your image. Use this ID as
the parameter to chenzj/dfimage
:
docker run -v /var/run/docker.sock:/var/run/docker.sock --rm chenzj/dfimage <IMAGE_ID>
如果您觉得太难了,那就拉 chenzj / dfimage
图片,然后
使用以下 docker-get-dockerfile.sh
脚本:
If you find this too hard just pull the chenzj/dfimage
image and then
use the following docker-get-dockerfile.sh
script:
#!/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"
您需要传递图像名称作为参数。用法示例:
You need to pass image name as the parameter. Example usage:
$ ./docker-get-dockerfile.sh alpine
FROM alpine:latest
ADD file:fe64057fbb83dccb960efabbf1cd8777920ef279a7fa8dbca0a8801c651bdf7c in /
CMD ["/bin/sh"]
这篇关于如何找出Docker映像的基本映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!