How to free up space on docker devmapper and CentOS7?
You can use:
docker system prune -a -f --volumes
where:
- -a == removes all unused images
- -f == force
- --volumes == prune volumes.
see: https://docs.docker.com/engine/reference/commandline/system_prune/#description
as a side note, I had a lot of issues when I used devicemapper driver on my environment. I used to clean as I mentioned, but there were still other devicemapper issues. I strongly recommend moving to overlay2, it solved almost everything completely.
Docker Devmapper space issue - increase size
Was able to get it working and have mentioned it in
https://forums.docker.com/t/devmapper-space-issue/29786/3
Clean docker environment: devicemapper
Don't use a devicemapper loop file for anything serious! Docker has big warnings about this.
The /var/lib/docker/devicemapper/devicemapper
directory contains the sparse loop files that contain all the data that docker mounts. So you would need to use lvm tools to trawl around them and do things. Have a read though the remove issues with devicemapper, they are kinda sorta resolved but maybe not.
I would move away from devicemapper
where possible or use LVM thin pools on anything RHEL based. If you can't change storage drivers, the same procedure will at least clear up any allocated sparse space you can't reclaim.
Changing the docker storage driver
Changing storage driver will require dumping your /var/lib/docker
directories which contains all your docker data. There are ways to save portions of it but that involves messing around with Docker internals. Better to commit and export any containers or volumes you want to keep and import them after the change. Otherwise you will have a fresh, blank Docker install!
Export data
Stop Docker
Remove
/var/lib/docker
Modify your docker startup to use the new storage driver.
Set--storage-driver=<name>
in/lib/systemd/system/docker.service
or/etc/systemd/system/docker.service
or/etc/default/docker
or/etc/sysconfig/docker
Start Docker
Import Data
AUFS
AUFS is not in the mainline kernel (and never will be) which means distro's have to actively include it somehow. For Ubuntu it's in the linux-image-extra
packages.
apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
Then change the storage driver option to --storage-driver=aufs
OverlayFS
OverlayFS is already available in Ubuntu, just change the storage driver to --storage-driver=overlay2
or --storage-driver=overlay
if you are still using a 3.x kernel
I'm not sure how good an idea this is right now. It can't be much worse than the loop file but
The overlay2
driver is pretty solid for dev use but isn't considered production ready yet (e.g. Docker Enterprise don't provide support) but it is being pushed to become the standard driver due to the AUFS/Kernel issues.
Direct LVM Thin Pool
Instead of the devicemapper loop file you can use an LVM thin pool directly. RHEL makes this easy with a docker-storage-setup
utility that distributed with their EPEL docker package. Docker have detailed steps for setting up the volumes manually.
--storage-driver=devicemapper \
--storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool \
--storage-opt dm.use_deferred_removal=true
Docker 17.06+ supports managing simple direct-lvm
block device setups for you.
Just don't run out of space in the LVM volume, ever. You end up with an unresponsive Docker daemon that needs to be killed and then LVM resources that are still in use that are hard to clean up.
docker container runnig out of space
Create the directory on the mount:
mkdir -p /mnt/data/docker-data
Create or edit your /etc/docker/daemon.json
and add set the following option(official documentation here):
{
"data-root": "/mnt/data/docker-data"
}
Reload and restart the docker daemon:
systemctl daemon-reload && systemctl restart docker
Related Topics
Removing Sensitive Data from Git. "Fatal: Ambiguous Argument 'Rm'"
Bash: Run an Executable File in Background
Diolan Dln-2 Spi Controller on X86_64 Platform
Shell Script to Kill the Process Listening on Port 3000
How to Make a Computer Behave as a Bluetooth Hid Device
What Do the .Eh_Frame and .Eh_Frame_Hdr Sections Store, Exactly
Run ASP.NET Core App Under Linux on Startup
Aws-Ec2, How to Set Multiple Public Sites with Just One Instance
How to Output Return Code in Shell
Convert an Iso Date to Seconds Since Epoch in Linux Bash
Bpf Verifier Rejects Code: "Invalid Bpf_Context Access"
How to Export Symbol from Linux Kernel Module in This Case
How to Figure Out What Is Using a Linux Kernel Module
Differencebetween Ld_Library_Path and -L at Link Time
How to Identify the Particular Linux Flavor via Command Line
How to Dynamically Allocate Memory Using Assembly and System Calls Under Linux
How to Get All Parent Processes and All Subprocesses with 'Pstree'