Docker containers can be used for multiple purposes such as application deployment or service hosting. The number of containers that can be hosted in a machine depends on the total disk space available.
For cost-effective hosting purposes, it is often required to restrict the individual docker container size. This limitation is also useful to ensure that a single user do not use up the entire disk space in the host machine.
Setup and manage your Docker system
A sneak-peak into Docker storage drivers
The feature to limit container size is only supported in Devicemapper storage and not by other storage drivers of Docker. In Docker, the storage drivers are responsible for managing the container’s filesystem.
The storage drivers supported by Docker for its containers are Devicemapper, Overlay, AUFS, BTRFS and ZFS. You can choose the driver during Docker installation and change it later on, if required.
This storage driver is applicable for all the containers in that host. To know the storage driver used for your Docker, you can use the command ‘docker info’.
[ Are your spending too much time managing your Docker containers? Our Docker experts take care of your infrastructure and ensure its smooth functioning. ]
What are the default Docker container size limits?
In Docker, there is a storage pool where the Docker containers are created. While using Defaultmapper storage, the storage pool size that is created is of default size 100 GB, as shown in the ‘Data Space Total‘ field in ‘docker info’.
Likewise, there is a default limit of 10 GB size set for the containers. This is the maximum size up to which a container can grow, and is defined by the parameter ‘Base Device Size‘. Increasing the container size limit is possible, as long as its within the pool limit.
When this default limit for docker container size is increased in Docker, it will impact the size all newly created containers. It is also possible to increase the storage pool size to above 100GB.
Here, we’ll see how to configure devicemapper storage option to set the container size and storage pool limits in Docker.
Increase default limits for docker container size and storage pool
Over time, it is probable that the disk space allotted to your docker containers is not sufficient for your business purposes. You may also want to increase the size of the storage pool so that you can create more containers for your growing business needs.
To increase the docker container size limits, the first requirement is to have enough disk space in the host machine.
Suppose you have enough space in /var partition and you need to increase storage pool size and docker container size limit. Here’s how to do it:
How to increase Docker storage pool size limit
To increase the overall storage pool size of Docker machine, follow these steps:
1. Backup all the existing Docker containers and images that you need and copy them to an external location.
2. Stop the Docker daemon.
3. Clear the current Docker default directory, which will delete all existing containers and images.
4. Create the storage directory “/var/lib/docker/devicemapper/devicemapper”.
5. Create the storage pool with your required new size, say 300 GB using the command:
dd if=/dev/zero of=/var/lib/docker/devicemapper/devicemapper/data bs=1G count=0 seek=300
6. Restart the Docker daemon with Devicemapper storage driver support.
7. Confirm the new storage pool size from the ‘Data Space Total’ in ‘docker info’.
How to increase Docker container size limit
The minimum size of docker containers is 10 GB and its not possible to decrease it further. But you can increase the docker container size from 10 GB it to a higher value, say 20 GB, with these steps:
1. Stop the Docker daemon after taking backup of existing containers and images.
2. Reset the Docker default directory.
3. Start Docker service with the parameter ‘dm.basesize’ set for the new value for Docker container size limit.
dockerd --storage-opt dm.basesize=20G
The newly created containers will now have their size limits set to 20 GB.
[ Running a Docker infrastructure doesn’t have to be hard, or costly. Get world class Docker management services at affordable pricing. ]
Change Docker default directory to expand space
The default docker directory is ‘/var/lib/docker’. This is the directory where the storage pool is located. The pool size is limited by the size of the ‘/var’ partition.
In situations where the /var partition gets filled up as more and more containers are created, the Docker storage may soon run out of space.
It is usually difficult to re-partition the host machine and allocate more disk to /var, which makes it impossible to assign more space to the storage pool.
But, there is a workaround by changing this directory to another partition with enough space. To know how to do it, check out our post ‘How to change Docker directory’.
Clear Docker cache to save disk space
Usually the docker container size expansion is required in scenarios where the disk usage is high and there isn’t enough space for hosting an application or a service in it.
But changing the size limits and directory settings of existing containers involves data loss. The size limit changes will affect all the containers that would be created in that host machine.
Also, in some Docker machines, there may not be enough disk space available in the host to increase the limits or add a new default directory.
So, in all these cases, increasing docker container size is not a solution for the disk space issue. Instead, a practically feasible solution we implement is removing the unwanted images and containers, which helps save the disk space allotted to them.
Clearing the Docker cache also helps to save some disk space. To know how we clear cache and remove dangling images in Docker, check out our post ‘How to clear Docker cache and save disk space‘.
[ Use your time to build your business. We’ll take care of your customers. Hire Our Docker Support Specialists at affordable pricing. ]
In short..
Today we saw how to increase Docker container size and storage pool default limits. If there is any valuable data, always take proper backups of containers before making any changes.
If the host machine itself is running out of disk space, then the only option is to resize the partition and then set up a new Docker system and migrate the containers.
Straightaway increasing the docker container size limits for a disk space issue is not recommended, as it can lead to wastage of disk space. So, try clearing the cache and unwanted containers, before changing the limits.
Proper resource planning is very important to save costs without compromising the business needs. If you’d like to know how to manage your Docker infrastructure to get the best out of them for your business, we’d be happy to talk to you.
0 Comments