Move Docker To Another Location on Linux

October 17th, 2018

Docker can take a toll on your disk space.

Fortunately you don’t have to keep the files in /var/lib/docker and on certain cloud providers like Digital Ocean it’s cheaper to attach a new block volume than to upgrade a droplet to get more disk space.

After you’ve decided on a location, simply do:

# systemctl stop docker
# mkdir /new/path/docker
# rsync -aqxP /var/lib/docker/ /new/path/docker

Change /lib/systemd/system/docker.service:

ExecStart=/usr/bin/dockerd -g /new/path/docker -H fd://


# systemctl daemon-reload
# systemctl start docker

When you’ve verified things are working, remove the old docker directory.

# rm -r /var/lib/docker


1 Comment

  1. Thanks for this post, Piero.

    It actually seems that at least in docker release 19.03, the way to go is slightly different (the above method does not work).


    # edit /etc/docker/daemon.json (if it doesn’t exist, create it) and include:
    "data-root": "/new/path/to/docker-data"

    # then restart Docker with:
    sudo systemctl daemon-reload
    sudo systemctl restart docker

    See the third answer at,
    or this blog post:

    Comment by guglielmocelata — October 4, 2019 @ 1:07 pm

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.