Skip to content

Instantly share code, notes, and snippets.

@ai2ys
Last active January 9, 2022 16:33
Show Gist options
  • Save ai2ys/5b2376a7755453fa5da7befcdddd3baa to your computer and use it in GitHub Desktop.
Save ai2ys/5b2376a7755453fa5da7befcdddd3baa to your computer and use it in GitHub Desktop.
Docker - moving Docker data directory to an other location

Moving the Docker data directory - Ubuntu 20.04

Resources

# work as root
sudo su

# specify the new location here
new_location=<new docker data location>

# stop docker daemon
service docker stop

# check /etc/docker/daemon.json
cat /etc/docker/daemon.json

# create new directory for docker 
mkdir -p ${new_location}

# copy current docker data to new location
rsync -aP /var/lib/docker ${new_location}

# edit /etc/docker/daemon.json and add entry "data-root":"<new docker data location>/"
# check file afterwards
cat /etc/docker/daemon.json

# rename old docker data location
mv /var/lib/docker /var/lib/docker.old

# start docker service
service docker start

# check which data-root directory `Docker Root Dir` is used before deleting it the old one
docker info

# test with hello-world
docker run hello-world

# delete old directory
rm -rf /var/lib/docker.old

# exit sudo su
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment