简体   繁体   English

Docker构建留下了中间图像

[英]Docker build leaves intemediate images

I want to build on my own composer:latest image with Docker version 18.06.1-ce, I use this script to do it: 我想建立自己的作曲家:Docker版本18.06.1-ce的最新图像,我用这个脚本来做:

#!/bin/sh

wget -O Dockerfile https://raw.githubusercontent.com/composer/docker/edf4f0abf50da5d967408849434b9053a195b65f/1.7/Dockerfile
wget -O docker-entrypoint.sh https://raw.githubusercontent.com/composer/docker/master/1.7/docker-entrypoint.sh
chmod +x docker-entrypoint.sh
docker build -t mycomposer:latest .

but besides the created image 但除了创建的图像

mycomposer:latest mycomposer:最新

i end up having around 10 images none:none. 我最终得到了大约10张图片无:无。

docker image prune

does not solve the issue. 没有解决问题。

how to build the composer:latest image form the files here composer github without leaving these intermediate images? 如何构建作曲家:最新的图像形成文件在这里作曲家github而不留下这些中间图像?

I want to do it manually instead of using command FROM because this is the first step of me using Dockerfile as a template and add,delete commands to/from it where I want. 我想手动而不是使用命令FROM,因为这是我使用Dockerfile作为模板的第一步,并在我想要的地方添加,删除命令。 But the first step is to get the image build as it is from local Docker file instead of using FROM command. 但第一步是从本地Docker文件中获取映像,而不是使用FROM命令。 I don't want to use FROM command because it implies using all the commands in Dockerfile and i want just a few of them as a starting point to my custom Dockerfile and some others edited from which I'll be building my own image. 我不想使用FROM命令,因为它意味着使用Dockerfile中的所有命令,我只想要其中一些作为我的自定义Dockerfile的起点,而其他一些编辑我将构建我自己的图像。

currently I managed to build image using local Dockerfile but there is a lot of unnecessary images none:none 目前我设法使用本地Dockerfile构建映像,但是有很多不必要的映像:none:none

实际存储库

instead of having repository like that: 而不是像那样的存储库: 在此输入图像描述

where there is just one image after build. 构建后只有一个图像的地方。 The single image from the picture above comes from the command: 上图中的单个图像来自命令:

docker pull composer:latest docker pull composer:最新

but this pulls composer image instead of building it from my local Dockerfile, so it does not fill the bill. 但这会拉动作曲家图像,而不是从我的本地Dockerfile构建它,因此它不会填满账单。

But how come there is just single image after the command pull and several ones after doing build from the same Dockerfile as pull takes (I assume) and how to get rid of these none:none images? 但是,为什么在命令拉动之后只有单个图像,并且在使用相同的Dockerfile进行构建之后有几个像拉取(我假设)以及如何摆脱这些无:无图像?

The images are the build cache. 图像是构建缓存。 They allow docker to dramatically speed up future builds of the same image. 它们允许docker大大加快同一图像的未来构建。 Their actual disk usage is near 0 because the layers are shared between the images, the only impact is some json metadata and directories. 它们的实际磁盘使用率接近0,因为图像之间共享图层,唯一的影响是一些json元数据和目录。 Once you build another image and untag the previously built image, a prune will remove the unused dangling images. 一旦你构建了另一个图像并取消了之前构建的图像,修剪将删除未使用的悬空图像。

Docker images are made of layers ; Docker图像由图层组成 ; each has a piece of the combined ultimate image filesystem. 每个都有一个组合的终极图像文件系统。 The layers actually make up a kind of tree, where you might have a base Ubuntu layer, with a child that installs a specific Debian package, with a child that adds your application code, and so on. 这些层实际上构成了一种树,在这种树中,您可能有一个基本的Ubuntu层,一个安装特定Debian软件包的子项,一个添加应用程序代码的子项,依此类推。 Each of these layers is actually independently usable as an image, but you can't delete a base-layer image so long as there's another image below it that depends on it. 这些图层中的每一个实际上都可以独立地用作图像,但只要在其下面有另一个图像依赖于它,就不能删除基础图层图像。

You're running docker image -a , which lists all of the images, even the ones that only exist as base layers. 您正在运行docker image -a ,它列出了所有图像,甚至是仅作为基础图层存在的图像。 That produces a bunch of "extra" <none> <none> images, which are the base layers. 这会产生一堆“额外” <none> <none>图像,它们是基础图层。 They're harmless, and required, and don't take up any extra resources. 它们是无害的,并且是必需的,并且不占用任何额外的资源。 In general using the -a option doesn't really tell you anything and I'd just skip it. 通常使用-a选项并不能真正告诉你任何事情,我只是跳过它。

My approach is to build an image from Dockerfile: 我的方法是从Dockerfile构建一个图像:

clone the repo from the github. 克隆来自github的repo。

git clone https://github.com/composer/docker.git .
cd 1.7 
docker build -t mycomposer:latest .

That's it. 而已。

Please refer to https://docs.docker.com/engine/docker-overview/#docker-objects 请参阅https://docs.docker.com/engine/docker-overview/#docker-objects

Each instruction in a Dockerfile creates a layer in the image. Dockerfile中的每条指令都在图像中创建一个图层。 When you change the Dockerfile and rebuild the image, only those layers which have changed are rebuilt. 更改Dockerfile并重建映像时,仅重建已更改的那些层。 This is part of what makes images so lightweight, small, and fast, when compared to other virtualization 与其他虚拟化相比,这是使图像如此轻量,小巧和快速的部分原因

Hence docker image prune won't remove them. 因此, docker image prune不会删除它们。 Without those layers, your image won't work. 没有这些图层,您的图像将无法使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM