我可以运行 Docker 映像的中间层吗? [英] Can I run an intermediate layer of a Docker image?
问题描述
当我从存储库中获取 Docker 映像时,我看到它提取了一堆带有一些 id 的层,但是当我尝试使用 docker run 运行它们时,它告诉我它不能找到它.
When I fetch a Docker image from a repository I see that it pulls a bunch of layers with some ids, but when I try to run them using docker run it tells me that it can't find it.
我可以运行一个我可以通过 docker history < 看到的 Docker 镜像的某一层吗?image_id >,就像古生物学家在挖掘有趣的东西一样?
Can I run a certain layer of a Docker image that I can see through docker history < image_id >, like a paleontologist digging to find something interesting?
我尝试了什么:
docker pull ruby
Using default tag: latest
latest: Pulling from library/ruby
693502eb7dfb: Already exists
081cd4bfd521: Already exists
5d2dc01312f3: Already exists
54a5f7da9a4f: Pulling fs layer
168cf3f33330: Pulling fs layer
021d84fef638: Pulling fs layer
168c3c107cd1: Waiting
f001b782a027: Waiting
然后:
docker run --rm -it 5d2dc01312f3 bash
Unable to find image '5d2dc01312f3:latest' locally
当我提取已构建并发布的图像时,我突然想到了这个问题.我可以清楚地看到一层有将近 1.2 GB 的大小.这是我从用于构建映像的机器中复制一些文件的层,在下一层我清理并删除了一些文件,因为我正在清理映像,但映像的总大小约为 1.5 GB意味着存在 1.2 GB 的大脂肪层.我就是想看看能不能看到那层脂肪.
The question popped to me when I was pulling an image that I have build and published. I could see it clearly that one layer had almost 1.2 GB of size. It was the layer where I copied some files from the machine I used to build the image and on the next layer I cleaned and deleted some of those files as I was cleaning the image, but the total size of the image was about 1.5 GB which means that the big fat layer is of 1.2 GB is there. I just want to see if I can peek into that fat layer.
推荐答案
您可以运行 Docker 层的中间 image,这可能是您想要的.
You can run an intermediate image of a Docker layer, which is probably what you want.
在构建过程中,您可能需要在构建过程中的某个点(步骤)检查图像,例如在您的 Docker 构建输出中,您会看到:
During your build you might need to inspect an image at certain point (step) in the build process e.g. in your Docker build output you'll see:
Step 17/30 : RUN rm -rf /some/directory
---> Running in 5ab963f2b48d
其中 5ab963f2b48d
是图像 ID,当您列出图像时,您会在列表中看到该 ID,例如
Where 5ab963f2b48d
is an image ID, and when you list your images, you'd see that ID in the list e.g.
$ docker image ls --all
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 5ab963f2b48d 7 minutes ago 1.18GB
例如,要运行该图像(使用终端),您可以简单地:
To run that image (with a terminal) for example, you can simply:
docker run -i -t 5ab963f2b48d /bin/bash
另请参阅:将 Docker 映像作为容器运行
这篇关于我可以运行 Docker 映像的中间层吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!