I want to try a new host provider which is cheap, fast and reliable. So I recently changed my test server.
New host provider provides 4 times more ram and NVMe storage, Sounds good but it is too begin to make a comparison , because I don’t have a any idea about reliability and they how to manage the problems.
Okay I bought new server from new provider, I made a optimization on server, which is remove un used some stuck services to save more ram, upgrade packages - kernel and take a some security actions.
New server is ready to serve my services but its empty. I need to move docker containers to new server. I think its very easy to move docker containers because files of containers stored at one folder.
So let’s begin to start move containers to new server
Take a backup
Firstly I personally recommend make a server backup to prevent any data loss. You can make backup on cloud provider or like a me backup over network via some online guides or some tools. I made backup with my own software https://github.com/AhmetOZER/HTTP-disk-image-backup but its too early to recommendation for a now.
After the taking backup check your backup is doesn’t have a any problem.
Install Docker on New Server
Install docker on new server before copying any data to new server. If you don’t Install docker before moving all containers to new server you may cause problem at Installing stage or service start stage.
Example scenario for Installing stage. All files are located but installer try to allocate same file at same location. Installer may crash.
Example situation for service start stage. Old server files changed by installer and your docker service not work properly.
Backup Container Folder on New Server
In new server also has a container directory. You can backup this folder or if it’s not required you can just remove it.
mv /var/lib/docker /var/lib/docker-backup
We will use a rsync application for the copying files. You need to install rsync on both server.
Note : If you are not a root user don’t forget to sudo command before run package manager.
# Ubuntu, Debian
apt install rsync
# CentOS, Fedora, RedHat
yum install rsync
apk add rsync
Stop Docker Service
You may stop docker on old server to prevent to miss some log or action based files changes while backup if the containers still run. You have to stop docker on new server to prevent any conflict.
service docker stop
Now we are ready to move container files to new server. For the moving we are using rsync application. Explanitons of
rsync -avzhp command flags.
-v increase verbosity
-z compress file data during the transfer
-h output numbers in a human-readable format
-p preserve permissions
-e specify the remote shell to use
One single command is enough to move all container to move new server.
rsync -avzhp root@old-server-ip-or-domain:/var/lib/docker/ /var/lib/docker/
if you are using specific port on ssh server you can use -e flag to delegate your custom port.
rsync -avzhp -e "ssh -p 1234" root@old-server-ip-or-domain:/var/lib/docker/ /var/lib/docker
Copy Old Server Docker Configuration Files, Personal or Data folders
We are only copied containers but if we have a some data or some specific Configurations on old server we may copy that.
For the copying we can again use rsync application.
# if you want to copy root folder
rsync -avzhp root@old-server-ip-or-domain:/root/ /root
# if you have a Specified docker configurations
rsync -avzhp root@old-server-ip-or-domain:/etc/docker/ /etc/docker
# You can write own command to copy folders
rsync -avzhp root@old-server-ip-or-domain:/my/custom/folder/ /my/custom/folder
Start Docker on New Server
Everything is nearly done. Just one step is required for start containers if you don’t have specific conditions.
service docker start
Your docker service will be start.
If you have pre configured network conditions like a IPv6 in containers you may have connection issue inside the containers. You need redelegate your IPv6 network in docker network and docker containers.
Thanks for the reading.