Skip to content

Instantly share code, notes, and snippets.

@zeagord zeagord/

Last active Apr 17, 2017
What would you like to do?
How to change the default docker image location in a virtual machine


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:

  1. sudo service docker stop
  2. sudo rm -rf /var/lib/docker/
  3. 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.

  1. Stop the Docker service if it is already running
sudo service docker stop
  1. 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
  1. Move the /var/lib/docker directory to your new partition
sudo mv /var/lib/docker /mnt/pd0/docker
  1. Make a symlink to the new mount point
sudo ln -nfs /mnt/resource/docker /var/lib/docker
  1. Take a look at the directory to see and verify whether the symbolic link has been created
sudo ls -l /var/lib/docker
  1. Start docker service again
sudo service docker start
  1. Restart your containers

  2. Check the mounted volume size using

df -h


Referred and Modified from:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.