Last active
May 19, 2020 22:43
-
-
Save emanuelhfarias/fe415d722174604dc5c8b833029ae09d to your computer and use it in GitHub Desktop.
How to change the Docker Images directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# How to change the Docker images directory (default dir=/var/lib/docker) | |
# The simplest method is to create a symbolic link that maps your destination partition and the original docker images directory | |
# see REF: https://forums.docker.com/t/how-do-i-change-the-docker-image-installation-directory/1169 | |
# remove all containers | |
docker ps -aq | xargs docker rm | |
# stop docker daemon | |
systemctl stop docker | |
# move all images from /var/lib/docker to the destination partition/dir (mount it first) | |
mv /var/lib/docker $destination | |
# create a symbolic link that maps your destination and the original docker images directory | |
ln -s $destination /var/lib/docker # the symbolic link must be in /var/lib/ with the name: 'docker' pointing to $destination | |
# start docker daemon | |
systemctl start docker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The preferred way nowadays is to create /etc/docker/daemon.json file and add:
Storage Driver tips:
EXT4 -> use overlay2
NTFS -> use devicemapper
To change the Storage Driver that Docker uses, add to /etc/docker/daemon.json file:
to automount partitions, add to /etc/fstab:
/dev/disk/by-uuid/xxx-xxx-xxx /mnt/store ext4 rw,suid,dev,exec,auto,async 0 0
On fedora, prefer /run/media/store
If system asks password to open store, just change ownership:
sudo chown user:user /mnt/store