Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate images with same id in Docker

Tags:

docker

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

My Dockerfile in linux folder

FROM ubuntu

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

Why this duplicity?

like image 718
Chen Hanhan Avatar asked Aug 20 '17 06:08

Chen Hanhan


People also ask

How do I duplicate an image in docker?

In order to transfer a Docker image from one server to another, what you need to do is first export the image to a file, then copy that file over from your current server to the new one using scp or rsync and finally load the image to your new server.

Can two docker images have the same name?

Multiple tags may refer to the same image. If you reassign a tag that is already used, then the original image will lose the tag, but will continue to exist (it will still be accessible by its image ID, and other tags might refer to it).

Can a single docker container have multiple images?

In later versions of Docker, it provides the use of multi-stage dockerfiles. Using multi-stage dockerfiles, you can use several base images as well as previous intermediate image layers to build a new image layer.

Can docker images be copied?

When using docker-machine, you can do docker $(docker-machine config mach1) save <image> | docker $(docker-machine config mach2) load to copy images between machines mach1 and mach2.


1 Answers

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

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.

You can do below

docker tag ubuntu ubuntu_my

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.

like image 181
Tarun Lalwani Avatar answered Oct 09 '22 10:10

Tarun Lalwani