Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does a running Docker container run out of disk space?

I've read through so much documentation, and I'm still not sure how this really works. It's a bit of a Docker vs. VM question.

If I start a VM with a 2GB hard drive and fill its disk with files, I know it runs out after 2GB of files.

Does Docker work the same way? I would assume so. But from what I've read about "UnionFS" it seems like it does not run out of space.

So then why do Docker "volumes" exist? Is that automagically expanding Docker disk space transient in some way? Will the files I've saved inside of my Docker container disappear after a reboot? How about after restarting the container?

like image 573
Randy L Avatar asked Nov 16 '16 00:11

Randy L


1 Answers

Docker's usage (1.12+) depends on the Docker storage driver and possibly the physical file system in use.

TL;DR Storage will be shared between all containers and local volumes unless you are using the devicemapper storage driver or have set a limit via docker run --storage-opt size=X when running on the zfs or btrfs drivers. Docker 1.13+ also supports a quota size with overlay2 on an xfs backed file system.

Containers

For all storage drivers, except devicemapper, the container and local volume storage is limited by the underlying file system hosting /var/lib/docker and it's subdirectories. A container can fill the shared file system and then other containers can't write any more.

When using the devicemapper driver, a default volume size of 100G is "thin allocated" for each container. The default size can be overridden with the daemon option --storage-opt dm.basesize option or set on a per container basis with docker run --storage-opt size=2G.

The same per container quota support is available for the zfs and btrfs drivers as both file systems provide simple built in support for creating volumes with a size or quota.

The overlay2 storage driver on xfs supporta per container quotas as of Docker 1.13. This will probably be extended to ext4 when new 4.5+ kernels become standard/common and ext4 and xfs quotas share a common API.

Volumes

Docker volumes are separate from a container and can be viewed as a persistant storage area for an ephemeral container.

Volumes are stored separately from Docker storage, and have their own plugins for different backends. local is the default backend, which writes data to /var/lib/docker/volumes so is held outside of the containers storage and possible quota system.

Other volume plugins could be used if you wanted to set per volume limits on a local file system that supports it.

Containers will keep their own file state over a container restart and reboot, until you docker rm the container. Files in a volume will survive a container removal and can be mounted on creation of the new container.

like image 130
Matt Avatar answered Nov 01 '22 07:11

Matt