Ubuntu 16.04 Move Docker Root

Shell script to move the Docker Root directory on Ubuntu 16.04 Xenial. Get the script on GitHub or download directly.

To use this script simply edit the line /dockerdir_new='/docker/var/' to reflect your intended new Docker Root location and chmod +x move-docker-root.sh, then run with ./move-docker-root.sh.

Tested working on:

Client: Version: 17.05.0-ce API version: 1.29 Go version: go1.7.5 Git commit: 89658be Built: Thu May 4 22:10:54 2017 OS/Arch: linux/amd64

Server: Version: 17.05.0-ce API version: 1.29 (minimum version 1.12) Go version: go1.7.5 Git commit: 89658be Built: Thu May 4 22:10:54 2017 OS/Arch: linux/amd64 Experimental: false


#change paths below to suit your needs

set -e
dockerdir_new2=$(echo "$dockerdir_new" | sed 's/\//\\\//g')
systemctl stop docker
mkdir -p $dockerdir_new
rsync -a $dockerdir_old* $dockerdir_new
sed -i.bak "/ExecStart=\/usr\/bin\/dockerd \-H fd:\/\//c ExecStart=\/usr\/bin\/dockerd \-H fd:\/\/ -g ${dockerdir_new2}" /lib/systemd/system/docker.service
mv $dockerdir_old /var/lib/docker.bak/
ln -s $dockerdir_new /var/lib/docker
systemctl daemon-reload
systemctl start docker.service
printf '\n* The Docker systemd config has been backed up to /lib/systemd/system/docker.service.bak\n* A backup of the old Docker Root has been copied to /var/lib/docker.bak/\n\n'
docker info | grep 'Root Dir'


Disqus Comments Loading...

Recent Posts

Bittorrent IP Blocklists

In addition to using a VPN service, as an extra precaution I've been using the blocklist feature of my bittorrent… Read More

October 26, 2019 3:31 pm

FreeNAS Error Creating Pool

command '('gpart', 'create', '-s', 'gpt', '/dev/da8')' returned non-zero exit status 1. If you get this error while trying to create… Read More

June 7, 2019 3:44 pm

Change Grub Default Boot Entry on Linux Mint

I'm dual booting Windows and Linux Mint on my laptop. The grub default is to boot into Linux Mint, however… Read More

April 23, 2019 7:45 pm

How to Reset Secure Channel On Active Directory Domain Controller

When you're a little too careless about virtualizing your domain controllers, cloning, migrating, backing up and restoring, returning from vacation… Read More

April 21, 2019 8:14 am

Run Systemd Script Before System Shutdown

I tried to retain the NGINX FastCGI cache and have it persist across system reboots instead of being ephemeral by… Read More

April 20, 2019 10:14 am

Learn Systemctl Usage to Manage Systemd Service in Linux

Systemd is new service manager for Linux. It's a replacement for all previous init systems (SysV/SysVinit & Ubuntu's Upstart) and… Read More

April 20, 2019 7:55 am