是否有找到Docker映像基础映像的命令? [英] Is there a command to find out the base image of a Docker image?

查看:75
本文介绍了是否有找到Docker映像基础映像的命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇我的图像基于什么基础图像。似乎没有简单直接的方法可以做到这一点。例如,我想知道 openjdk:11-jdk 的基本图像。

I am curious about what base image my image is based upon. There seems no easy and straightforward way to do that. So for example I want to know the base image of openjdk:11-jdk.

首先,我通过执行
docker images |从本地存储库中获取相关的映像ID。

First of all, I am fetching the relevant image id from my local repository by doing docker images | grep openjdk, which gives me below output.

↳ docker images | grep openjdk
openjdk 11-jdk              612d4d483eee        8 days ago          606MB
openjdk <none>              3a40000f62f1        3 weeks ago         605MB
openjdk <none>              243e95d792e3        2 months ago        605MB

此处的相关图像为 612d4d483eee ,因此我想通过执行 docker history 612d4d483eee 查看该图像的历史记录,这使我获得了以下输出(我省略了- no-trunc 选项,因为它弄乱了格式)。

The relevant image here is 612d4d483eee, so I want to see the history of that image by doing docker history 612d4d483eee which gives me below output (I left out the --no-trunc option because it messes up the formatting).

↳ docker history 612d4d483eee
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
612d4d483eee        8 days ago          /bin/sh -c #(nop)  CMD ["jshell"]               0B                  
<missing>           8 days ago          /bin/sh -c set -eux;   dpkgArch="$(dpkg --pr…   322MB               
<missing>           8 days ago          /bin/sh -c #(nop)  ENV JAVA_URL_VERSION=11.0…   0B                  
<missing>           8 days ago          /bin/sh -c #(nop)  ENV JAVA_BASE_URL=https:/…   0B                  
<missing>           8 days ago          /bin/sh -c #(nop)  ENV JAVA_VERSION=11.0.6      0B                  
<missing>           3 weeks ago         /bin/sh -c { echo '#/bin/sh'; echo 'echo "$J…   27B                 
<missing>           3 weeks ago         /bin/sh -c #(nop)  ENV PATH=/usr/local/openj…   0B                  
<missing>           3 weeks ago         /bin/sh -c #(nop)  ENV JAVA_HOME=/usr/local/…   0B                  
<missing>           3 weeks ago         /bin/sh -c #(nop)  ENV LANG=C.UTF-8             0B                  
<missing>           3 weeks ago         /bin/sh -c set -eux;  apt-get update;  apt-g…   9.68MB              
<missing>           3 weeks ago         /bin/sh -c apt-get update && apt-get install…   142MB               
<missing>           3 weeks ago         /bin/sh -c set -ex;  if ! command -v gpg > /…   7.81MB              
<missing>           3 weeks ago         /bin/sh -c apt-get update && apt-get install…   23.3MB              
<missing>           3 weeks ago         /bin/sh -c #(nop)  CMD ["bash"]                 0B                  
<missing>           3 weeks ago         /bin/sh -c #(nop) ADD file:8f7dc710e276f54a3…   101MB 

我可以看到图像的各层,但看不到基本图像。

I can see the layers of the image, but I see no base image.

我通常要做的是转到Docker集线器页面条目( https://hub.docker.com/_/openjdk ),看看是否在任何地方都提到了一个存储库。

What I usually do is going to the Docker hub page entry (https://hub.docker.com/_/openjdk) and see if there is a repository mentioned anywhere.

幸运的是,在这种情况下,有一个Github存储库,它是 https://github.com/docker-library/openjdk 。因此,我转到该存储库并导航到我的特定映像的Dockerfile( https://github.com/docker-library/openjdk/blob/master/11/jdk/Dockerfile )。在该文件的顶部,我看到以下行:

Luckily in this case there is a Github repository which is https://github.com/docker-library/openjdk. So I go to that repository and navigate to the Dockerfile of my specific image (https://github.com/docker-library/openjdk/blob/master/11/jdk/Dockerfile). On top of that file, I see the following line:

FROM buildpack-deps:stretch-scm

所以问题是为什么 buildpack-deps:stretch-scm 为什么不在命令输出中的任何地方都可见?最重要的是,我想知道是否有一种更简单的方法来查找基本图像。

So the question is why is buildpack-deps:stretch-scm not visible anywhere in my command outputs? On top of that I want to know if there is an easier way of finding out the base image.

推荐答案

对于拉出的图像,我不认为没有找到实际dockerfile的方法就可以找到基本映像,因为当您拉取映像时,映像清单仅针对叶层下载。因此,在 docker历史记录中,非叶子层的图像ID在标记为< missing> 时,您不会不知道这些层的回购标签。

For pulled images, I don't think there is a way to find the base image without seeing the actual dockerfile because when you pull an image, image manifest is downloaded only for the leaf layer. So the image id of the non-leaf layers in marked as <missing> in docker history and you wouldn't know the repo tags of those layers.

如果映像是在您的计算机上构建的,但是如果您没有dockerfile,则可以找到基本映像如下:

If the image is built on your machine but if you don't have the dockerfile, you can find the base image as follows:

docker history 打印图层的图像ID。然后,您可以使用 docker inspect 获取回购标签。使用的基本映像通常是 docker history 输出的最后一层。

docker history prints the image ids of the layers. Then you can get the repo tags using docker inspect. The base image used will usually be the last layer in the output of docker history.

例如:

$ docker history t:1
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
10b4cce00fb8        3 days ago          /bin/sh -c #(nop)  CMD ["flask" "run"]          0B
824987ef6cab        3 days ago          /bin/sh -c #(nop) COPY dir:1973b65388e92428e…   406B
d4b6f433a5df        3 days ago          /bin/sh -c pip install -r requirements.txt      4.98MB
8827b3f01d00        3 days ago          /bin/sh -c #(nop) COPY file:98271fcaff00c6ef…   0B
65b8c98138e6        2 weeks ago         /bin/sh -c apk add --no-cache gcc musl-dev l…   113MB
01589531f46d        2 weeks ago         /bin/sh -c #(nop)  ENV FLASK_RUN_HOST=0.0.0.0   0B
6c4640b8027a        2 weeks ago         /bin/sh -c #(nop)  ENV FLASK_APP=app.py         0B
b4c8fc7f03d6        2 weeks ago         /bin/sh -c #(nop) WORKDIR /code                 0B
16a54299f91e        2 weeks ago         /bin/sh -c #(nop)  CMD ["python3"]              0B



$ docker inspect 16a54299f91e
[
    {
        "Id": "sha256:16a54299f91ef62cf19d7329645365fff3b7a3bff4dfcd8d62f46d0c9845b9c6",
        "RepoTags": [
            "python:3.7-alpine"   ---> Base image used in FROM instruction. 

以下是 docker history 的输出命令,您可以大致重新创建Dockerfile。

Following the output of docker history in reverse order, you can approximately recreate the Dockerfile.

您还可以使用 chenzj / dfimage 图片运行一个用于重建dockerfile的脚本。

You can also use the chenzj/dfimage image which runs a script which does the same to reconstruct the dockerfile.

alias dfimage="docker run -v /var/run/docker.sock:/var/run/docker.sock --rm chenzj/dfimage"

$ dfimage 10b4cce00fb8
FROM python:3.7-alpine
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN /bin/sh -c apk add --no-cache gcc musl-dev linux-headers
COPY file:98271fcaff00c6efb6e58bd09ca726c29947e0cfe7031a8d98878cc01561fbbf in requirements.txt
RUN /bin/sh -c pip install -r requirements.txt
COPY dir:1973b65388e92428e30f835a67ebc8c7b00ec648fbea0717af6d501af162186b in .
CMD ["flask" "run"]
bash-3.2$

这篇关于是否有找到Docker映像基础映像的命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆