Limit Docker volume size

Dmitry Tkachuk
Oct 19 · 2 min read

How to easily create docker volumes with limited disk allocation.

Recently I've faced the problem - how to create Docker volumes that will be limited in size? For example, a want 50GB volume for my web application and 25GB volume for ElasticSearch container. Turns out that it’s not so easy. Docker documentation provides a few examples of advanced volumes usage with custom storage drivers here, but it looks like only tmpfs mounts support disk usage limitations.

So how to solve this problem?

TL;DR: Use Convoy plugin with devicemapper driver, but take into consideration that this project is not actively maintained or just switch to Kubernetes.

If you’re brave enough to use software that’s explicitly marked as DEPRECATED — you’re welcome!

First of all, you have to install Convoy on your machine:

Code Snippet #1 — Convoy Plugin Installation

Installation instructions are also available here.

Then we have to download and execute a script that will help us with setting up Device Mapper driver. $DISK_MOUNTPOINT variable should be replaced with the path to the disk that will be formatted and partitioned for Convoy to operate.

Code Snippet #2 — DeviceMapper partitioning helper

More info about using Convoy with devicemapper driver can be found here.

Now it’s time to run Convoy daemon (btw — don’t forget to unmount your disk if it was mounted to the system):

Code Snippet #2 — Running Convoy service

Also, it’s a good idea to turn convoy daemon into a service, here’s an example on the service file:

Code Snippet #3— Convoy service example

Update service file with your values if needed, place it into systemd services folder, enable and start:

Code Snippet #4 — Convoy service setup

After this check out convoy service status by running service convoy status.

Voilà, now you should be able to create docker volumes with predefined size:

Code Snippet #5 — Convoy service example

It’s that simple! Now you can check out newly created partitions by running fdisk -l command.


As we can see it’s possible to create docker volumes with a predefined size and do it from Docker API which is especially useful if you’re creating new volumes from some container with mounted docker socket and don’t have access to the host.

Limiting other machine resources in Docker is much simpler and could be done just by using built-in Docker capabilities:

You can learn more about Rancher Convoy in their GitHub repo:

All steps from the tutorial also available as a single gist.

If this article was helpful — clap and share 🙃. Thanks for reading!

Thanks to Chadwick Strange

Dmitry Tkachuk

Written by

Software Developer. Entrepreneur 💻

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade