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?
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.
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).
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With