Solution to Docker taking up disk space

  • 2020-06-12 11:34:41
  • OfStack

From the command you can see that /var/lib/Docker directory is very large, my host is only 20G, this directory takes up 18G; The reason is that the space of devicemapper is set too large. As can be seen from the Data Space Total parameter printed by docker info, the default is 107.4G.

The idea is as follows:

Backup the current container and image;

Delete /var/lib/docker directory;

Resize using the dd command;

Restore container and mirror;

Tools:

If you need extra space to save backup files, you can mount an u disk or cloud disk.

docker save can export mirror tar files;

docker export can export container tar files;

Stop docker after backup is done


# /etc/init.d/docker stop 

Delete /var/lib/docker directory;


# mkdir -p /var/lib/docker/devicemapper/devicemapper/data 
# dd if=/dev/zero of=/var/lib/docker/devicemapper/devicemapper/data bs=1M count=0 seek=8192 

The maximum number of files created is 1M * 8192 = 8G

Start the docker


# /etc/init.d/docker start 

Use docker info to look at Data Space Total and check to see if the setup was successful

docker load can import the mirror tar file as a mirror

Note the usage of load: docker load image1:new < image1.tar

docker import can import container tar files as mirrors

cat container1.tar |docker import-container1 :new


Related articles: