我可以运行Docker映像的中间层吗? [英] Can I run an intermediate layer of a Docker image?

查看:65
本文介绍了我可以运行Docker映像的中间层吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从存储库中获取Docker映像时,我看到它拉了一堆带有一些ID的层,但是当我尝试使用 docker run 运行它们时,它告诉我它不能找到它.

我可以运行通过 docker history<看到的Docker映像的特定层吗?image_id> ,就像古生物学家正在努力寻找有趣的东西吗?

我尝试过的事情:

  docker pull ruby使用默认标签:最新最新:从图书馆/红宝石拉693502eb7dfb:已经存在081cd4bfd521:已经存在5d2dc01312f3:已经存在54a5f7da9a4f:拉起fs层168cf3f33330:拉出fs层021d84fef638:拉出fs层168c3c107cd1:正在等待f001b782a027:正在等待 

然后:

  docker run --rm -it 5d2dc01312f3 bash无法在本地找到图像"5d2dc01312f3:latest" 

当我提取自己已建立并发布的图像时,这个问题突然出现.我可以清楚地看到一层的大小将近1.2 GB.在那一层中,我从用于构建映像的机器中复制了一些文件,然后在下一层上清理并删除了一些文件,因为我正在清理映像,但是映像的总大小约为1.5 GB,这相当于表示那里的大脂肪层为1.2 GB.我只想看看我是否可以窥视到那个脂肪层.

解决方案

您可以运行Docker层的中间 image ,这可能是您想要的./p>

在构建过程中,您可能需要在构建过程中的特定点(步骤)检查图像,例如在您的Docker构建输出中,您将看到:

 步骤17/30:RUN rm -rf/some/directory--->在5ab963f2b48d中运行 

其中 5ab963f2b48d 是图片ID,当您列出图片时,您会在列表中看到该ID,例如

  $ docker image ls --all储藏标签图像ID尺寸增加< none>< none>5ab963f2b48d 7分钟前1.18GB 

例如,要运行该图像(使用终端),您可以简单地:

  docker run -i -t 5ab963f2b48d/bin/bash 

另请参阅:将Docker映像作为容器运行

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.

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?

What I tried:

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

Then:

docker run --rm -it 5d2dc01312f3 bash
Unable to find image '5d2dc01312f3:latest' locally

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.

解决方案

You can run an intermediate image of a Docker layer, which is probably what you want.

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

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

Also see: Run a Docker Image as a Container

这篇关于我可以运行Docker映像的中间层吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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