Blog of science and life

Contact
Archives
Feed

Move Docker volumes to other server


New home

I've been self-hosted a few services for my daily needs, and I choosed Hetzner because of their's pricing.

But now after I know Contabo, I will move my services to Contabo, because it's cheaper and more powerful.

I can reduce the server cost for about 30%. Neet.

But I don't want to lose my data. And I don't want to spent a lot of time migrate things either.

Luckily, all of my projects was deployed using Docker. If you don't know Docker, now is good time to start because it's awesome.

Moving data

Let's say I want to move from server A (Hetzner) to server B (Contabo)

And my jobs now are:

  1. Generate ssh key (ssh-keygen -t ed25519) and add public key to server B ~/.ssh/authorized_keys file.
  2. rsync -av my projects from A to B
  3. Find the right directory where Docker bind volumes with docker inspect <container_name …
Read more

Move docker data to another location (Ubuntu)


Goal: I want to move my existing Docker data to new location (/mnt/Data), for more free space.

Solution:

  1. Stop Docker service
    sudo systemctl stop docker

  2. Edit /etc/docker/daemon.json and insert this

{
    "graph": "/mnt/Data/docker"
}
  1. Move old data to new location
    sudo rsync -aqxP /var/lib/docker /media/Data/

  2. Temporary move old data to other directory
    sudo mv /var/lib/docker /var/lib/docker.old

  3. Start docker service
    sudo systemctl start docker

  4. Check new config work
    docker info | grep -i root This should output new location

  5. Remove old data

  6. Profit

P/s: I'm using Docker version 20.10.6, build 370c289

Read more