在Docker中复制具有相同ID的图像 [英] Duplicate images with same id in Docker
问题描述
当我使用docker-compose文件下载映像时,映像被复制.这是我的docker-compose.yml
When I download the image with docker-compose file, the images are duplicated. Here is my docker-compose.yml
version: "3"
services:
ubuntu:
build: ./linux
container_name: ubuntu
stdin_open: true
tty: true
我在Linux文件夹中的Dockerfile
My Dockerfile in linux folder
FROM ubuntu
命令"$ docker images"的输出:
The output of the command "$docker images":
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest ccc7a11d65b1 9 days ago 120 MB
ubuntu_ubuntu latest ccc7a11d65b1 9 days ago 120 MB
为什么如此重复?
推荐答案
在您的Dockefile中,您使用了 FROM ubuntu
,因此您只是继承了该图像而未对其进行任何处理.因此,新映像仅与 ubuntu
映像相同.这就是为什么您看到相同的ID
In your Dockefile, you used FROM ubuntu
, so you just inherited the image and did nothing out of it. So the new image is nothing but the same as ubuntu
image. And that is why you are seeing the same id
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest ccc7a11d65b1 9 days ago 120 MB
ubuntu_ubuntu latest ccc7a11d65b1 9 days ago 120 MB
这并不意味着您从相同的两个图像中占用了 240MB
.这只是意味着 ubuntu
和 ubuntu_ubuntu
指向同一张图片,并且图片大小为 120 MB
.
It doesn't mean you have 240MB
occupied from same two images. It just means that ubuntu
and ubuntu_ubuntu
point to the same image and that image size is 120 MB
.
您可以在下面进行
docker tag ubuntu ubuntu_my
它将创建另一个具有该名称,相同ID和大小的条目.名称和标签只是对ID的引用.多个名称可以指向相同的ID.
And it will create another entry with that name and same ID and Size. Name and Tag are just reference to the ID. Multiple names can point to Same ID.
这篇关于在Docker中复制具有相同ID的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!