我可以运行docker映像的中间层吗? [英] Can I run an intermediate layer of docker image?
问题描述
当我从存储库中获取一个docker镜像时,看到它拉了一堆带有一些id的层,但是当我尝试使用 docker run 来运行它们时,它告诉我找不到
when i fetch a docker image from a repository a 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<< image_id> ,就像古生物学家在挖掘发现有趣的东西吗?
My question goes like this , can i run a certain layer of a docker image that i can see through docker history < image_id >, like 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.2go,这是我复制的那一层我用来构建映像的计算机中的一些文件,并在下一层上清理并删除了一些文件我正在清理图像时这些文件中有多少,但图像的总大小约为1.5go,这意味着大脂肪层约为1.2go,我只想看看我是否可以窥视该脂肪层。
the question poped to me when i was pulling an image that i have build and published and i could see it clearly that one layer had almost 1.2go of size and 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 total size of the image was about 1.5go which means that the big fat layer is of 1.2go 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屋!