We ran in to a lot of space issues with storing docker images in Azure cloud VMs. Because by default docker images, layers and containers are stored in the
It is the same with the Amazon AWS as well.
The problem with this is most of the virtual machines have a very limited space in the OS Disk and the space can run out very soon. It is wise to save the docker images and attach your data containers to point a mount volume.
So if you ever run in to space problems. Do the following steps:
- sudo service docker stop
- sudo rm -rf /var/lib/docker/
- sudo service docker start
If you do the above steps, you will be able to reclaim the spaces. But it is not ideal to remove the containers and images frequently.
So i started mounting my images in the data disks instead of OS disks which you can frequently schedule for a backup as well.
- Stop the Docker service if it is already running
sudo service docker stop
- Make a back up of the existing docker directory (Change your mount directory-> /mnt/resource)
sudo tar -zcC /var/lib docker > /mnt/resource/var_lib_docker-backup-$(date +%s).tar.gz
- Move the /var/lib/docker directory to your new partition
sudo mv /var/lib/docker /mnt/pd0/docker
- Make a symlink to the new mount point
sudo ln -nfs /mnt/resource/docker /var/lib/docker
- Take a look at the directory to see and verify whether the symbolic link has been created
sudo ls -l /var/lib/docker
- Start docker service again
sudo service docker start
Restart your containers
Check the mounted volume size using
Referred and Modified from: https://forums.docker.com/t/how-do-i-change-the-docker-image-installation-directory/1169