Docker Community Forums

Share and learn in the Docker community.

Migrating docker installation to another server, keep overlay data

Hello,

I am trying to migrate an existing docker installation to a new server.
I created a tar file from /var/lib/docker from the old host and unpacked the tar folder on the new host in /var/lib/docker.

It seems most space is utilized by the next folders:
/var/lib/docker/containers
/var/lib/docker/overlay2
/var/lib/docker/volumes

When starting the docker service on the new host i can start my old containers. BUT they do not contain any data. Is it possible to somehow get my old containers running on the new hosts and keeping their data persistent.

Once running on the new server i can create new containers and start using persistent volumes.

Thanks for your help guys :slight_smile:

It is important here that you have completely stopped docker daemon. The following linux command will yield no output only if docker service is stopped:

ps aux | grep -i docker | grep -v grep

If no output has been produced by the above command, reload systemd daemon:

systemctl daemon-reload

Once this is done create a new directory you specified above and optionally rsync current docker data to a new directory:

mkdir /new/path/docker

rsync -aqxP /var/lib/docker/ /new/path/docker

At this stage we can safely start docker daemon:

systemctl start docker

Confirm that docker runs within a new data directory:

ps aux | grep -i docker | grep -v grep

root 2095 0.2 0.4 664472 36176 ? Ssl 18:14 0:00 /usr/bin/docker daemon -g /new/path/docker -H fd://
root 2100 0.0 0.1 360300 10444 ? Ssl 18:14 0:00 docker-containerd -l /var/run/docker/libcontainerd/docker-containerd.sock --runtime docker-runc
All done.