Reputation: 2166
user@localhost:~/docker-pyzmq$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpinepyzmq_raw latest fd24a753f505 2 minutes ago 23.9MB
<none> <none> 3f763de0fb0b 7 minutes ago 23.9MB
alpinepyzmq_small latest c7a1f42d0bfd 14 minutes ago 94.8MB
alpinepyzmq latest 5be9ed0fcbcb 17 minutes ago 317MB
<none> <none> 97aa31fe216a 19 minutes ago 317MB
<none> <none> b167c481edc2 22 minutes ago 338MB
<none> <none> fe8504847607 29 minutes ago 304MB
<none> <none> 5b845a00f4d9 32 minutes ago 79.5MB
<none> <none> 2d6926b0c665 32 minutes ago 79.5MB
Does the output above mean alpinepyzmq_raw
can be run inside a computer and it'll just weight 23.9mb? Or is this size dependent on other layers? If so, how can I figure out the entire image size?
Upvotes: 7
Views: 9226
Reputation: 906
The docs can help to answer this question,
The SIZE
is cumulative space taken up by the image and all its parent images. This is also the disk space used by the contents of the Tar file created when you docker save an image.
Notice here that: An image will be listed more than once if it has multiple repository names or tags. This single image (identifiable by its matching IMAGE ID
) uses up the SIZE
listed only once.
Upvotes: 1
Reputation: 54
In docker images are created using dockerfile. Each image consists of multiple layers. Each layer corresponds to a certain instruction from dockerfile. Docker uses Union File System to mount these layers on top of each other. Therefore you can think of an image as the final layer built on top of multiple read-only layers (UFS). You can see the layers a docker image is based up on by docker image inspect -f '{{.RootFS.Layers}}' <image>
.
In general you want to keep your image size as low as possible, therefore use &&
in your dockerfile extensively. For example:-
You will want to prefer
From Ubuntu
RUN aptg-get update && apt-get install vim
rather than
From Ubuntu
RUN apt-get update
RUN apt-get install vim
as, since docker 1.10, the RUN
, ADD
and COPY
statements add a new layer to your image.
Also you should use multi-stage builds where you can use multiple base in same dockerfile, with each of them beginning new stage of build. With this, you can leave everything behind that you don't want in the final image.
The image size shown in the output above is the final image size, and yes you can run this image inside a container but that is not the final size of the container that is running this image. When you run a container from an image, you essentially create a read-write copy of that image inside the container. This is the container layer which allows modification of the entire copy of the image. Therefore your container can grow in size. You can see a container size using docker system df -v
Upvotes: 1
Reputation: 131396
Does the output above mean alpinepyzmq_raw can be run inside a computer and it'll just weight 23.9mb?
Image size and container size are two distinct things.
Image size :
When you execute docker image ls
, the column size is not necessarily the size of the image because that is the size of the current image + all these parent images :
The SIZE is the cumulative space taken up by the image and all its parent images. T 23.9
While for a base image without parent such as Alpine, you can consider that the image size.
In docker, parent images are not merged in each child images but stored in distinct layers to be shared.
To know the real size of an image (without the parent sizes), use docker history IMAGE
.
Container size :
The container size is not strictly equal to the image size.
Besides, containers use both memory (ram) and disk.
To know disk occupation size :
docker system df
That does echo to the famous df
linux command that shows used/free space on disks.
Upvotes: 6