Disk size of a docker image

12,975

Solution 1

A Docker container uses copy-on-write storage drivers such as aufs, btrfs, ... to manage the container layers. All writes done by a container are persisted in the top read-write layer. These layers (especially the write layer) are what determine a container's size.

There is a size limit to the Docker container known as base device size. The default value is 10GB. This value can be changed to allow the container to have more size using dockerd --storage-opt dm.basesize=50G. This will give the container a rootFS size of 50GB.

However, this is not the recommended way to handle heavy write operations that increase the container size. The recommnded way to do that is using Docker volumes. Volumes are not persisted within the Docker local storage area for container layers (i.e /var/lib/docker/<storage-driver>/...), and are thus independent from the container's storage driver. Therefore, they do not contribute to the size of the container.

There is no limits on the number of volumes a container can have. It is recommended to map directories inside the container that will grow in size into volumes.

For more info about storage drivers check About storage drivers

Note: for write-heavy applications, you should not store the data in the container. Instead, use Docker volumes, which are independent of the running container and are designed to be efficient for I/O. In addition, volumes can be shared among containers and do not increase the size of your container’s writable layer.

Solution 2

Use volumes mounted to the container for storage. That way the size of your containers does not become too big.

https://docs.docker.com/storage/volumes/

Share:
12,975

Related videos on Youtube

whoami
Author by

whoami

Updated on June 04, 2022

Comments

  • whoami
    whoami over 1 year

    As someone new to docker world and coming from a virtual machine mindset. I downloaded a docker image for elastic search from docker hub.I am thinking about any configurations I need to do because a lot of data will be forwarded to this image. I need to be considerate about the available disk space. In a Virtual machine world, I can always add additional vhds to increase disk size etc. What's similar operation in a docker world?