Docker&devicemapper initialize a 100GB sparse file (`/var/lib/docker/devicemapper/devicemapper/data`) to store images and containers. To check the available space inside that file you can run the following commands:
- `du -h /var/lib/docker/devicemapper/devicemapper/data`
- `ll -s /var/lib/docker/devicemapper/devicemapper/data`
- `docker info` -> Data Space Used/Data Space Total
Because there is a possibility that under certain conditions the space used by deleted images/containers is not reclaimed[1], we might need to enlarge the data file when it’s full.
Steps:
- Make sure there’s enough free disk space to:
- create backups of device mapper files in step 6 below
- enlarge the data file in step 7 below (the additional space will initially be unallocated/sparse, but we still need to make sure there’s enough space to actually use that space)
- Check which files are used by docker/devicemapper: `docker info` -> Data file, Metadata file, Data loop file, Metadata loop file
- `cd /var/lib/docker/devicemapper/devicemapper`
- Check that the mappings are set up: `losetup –all`, `losetup –associated data`, `losetup –associated metadata`
- Stop the docker daemon (`service stop docker`) and make sure that the mappings are gone (re-run the commands from step 2 above)
- Backup the files: `cp data data-backup`, `cp metadata metadata-backup`
- Enlarge the data file: `truncate –size=+50G data`
- Ensure that the operation has been successful: `du -h data`, `ll -s data`
- `service docker start`
[1] Related issues/articles:
- https://github.com/docker/docker/issues/3182
- https://github.com/docker/docker/issues/7105
- https://stackoverflow.com/questions/27853571/why-is-docker-image-eating-up-my-disk-space-that-is-not-used-by-docker
- https://docs.docker.com/reference/commandline/cli/#storage-driver-options
- https://jpetazzo.github.io/2014/01/29/docker-device-mapper-resize/
- https://github.com/docker/docker/blob/master/daemon/graphdriver/devmapper/README.md
- https://developerblog.redhat.com/2014/09/30/overview-storage-scalability-docker/