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

move-docker-root.sh

#!/bin/bash
#sysinfo.io
#change paths below to suit your needs
dockerdir_new='/docker/var/'
dockerdir_old='/var/lib/docker/'

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'

 

Share
Disqus Comments Loading...

Recent Posts

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

May 14, 2019 8:22 am 08:22

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 19:45

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 08:14

Run SystemD Script Before System Shutdown

for the sheer hell of it, a few weeks ago i wanted to see if i could properly and successfully… Read More

April 20, 2019 10:14 am 10:14

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 07:55

Force Delete Windows Server DHCP Failover Relationship

if you've found yourself here then chances are you messed up one of your domain controllers or at least one… Read More

April 20, 2019 5:54 am 05:54