How to Move Docker Containers to a New VPS Without Downtime
Moving to a cheaper provider, a closer region, or a box with more disk is one of the most common reasons people touch their Docker setup after the first install. Learning how to move Docker containers to a new VPS is not really about moving the containers themselves, since containers are disposable. It is about moving three things intact: your Compose files, your images, and the data inside your volumes.
This guide covers the full process: inventory, prepping the new VPS, backing up volumes, transferring images, cutting DNS over, and keeping a rollback path open. The goal is zero data loss and downtime measured in minutes.
Take inventory of what is actually running
Before touching anything, list every container, volume, network, and bind mount. People forget the little things: a single bind-mounted config directory that never made it into the Compose file, or an environment variable set only in the shell where the container was first started. If you are writing your first docker-compose.yml file, now is also a good time to make sure every service you run is actually defined in one.
docker compose ls
docker volume ls
docker network ls
# For each stack, save the resolved config including env vars:
docker compose config > /root/migration/old-server-compose-resolved.yml
docker compose config is worth running because it resolves all variable interpolation and prints the effective configuration. Store that output with your backups.
Also note which volumes are named and which are anonymous. Anonymous ones only appear when you inspect a running container, and they are the number one cause of silent data loss during a move. Check the Mounts section of docker inspect <container> for every container you care about.
Set up the new VPS before moving anything
Provision the new server, then install Docker Compose on Ubuntu 24.04 and match the Docker Engine version to the old server. A version jump in the same window as a migration makes troubleshooting harder, so pin both servers to the same release for the move and upgrade later.
Check disk space with headroom for the incoming data, and confirm the new server can actually handle it. A quick test of your disk and network speed on the new VPS before you copy gigabytes across it is worth the two minutes. A slow link between the two servers changes your whole timing plan, and it is better to discover that at 2pm than at 2am during the DNS cutover.
# On the NEW server
docker version
df -h /var/lib/docker
free -h # if RAM is tight, add swap before image imports
Back up the data, not just the images
Images are easy to replace. Data is not. For a docker volume backup, the simplest reliable method is a tar archive taken from a temporary container that mounts the volume. Never back up /var/lib/docker directly while the daemon is running; you will capture half-written files.
mkdir -p /root/migration/volumes
docker stop $(docker compose ps -q)
docker run --rm -v myapp_db_data:/data -v /root/migration/volumes:/backup
alpine tar czf /backup/myapp_db_data.tar.gz -C /data .
docker compose up -d
Repeat for every named volume, and do not skip the small ones. A 40 MB config volume feels unimportant until the container fails to start without it. Copy the whole project directories too: Compose files, .env files, and bind-mounted config folders.
Move the images with docker save and load
For a docker save load images transfer you have two realistic options. If the image comes from a public registry or one you control, skip the transfer entirely and let the new server docker compose pull it fresh. That is always the cleanest path. Save and load is for custom images you built locally and never pushed anywhere.
# On the OLD server: save custom images
docker save myapp/web:latest myapp/worker:latest | gzip > /root/migration/images.tar.gz
# Copy the bundle to the new server
scp /root/migration/images.tar.gz root@NEW_SERVER_IP:/root/migration/
# On the NEW server: load them back
docker load -i /root/migration/images.tar.gz
Large images over a slow link take a while. If the old server has spare CPU, gzip helps; if the link is fast, skip compression. For stacks over a few gigabytes, a temporary private registry container on the new server (push locally, then pull) can beat save/load, but for most cases scp of the tar bundle is simpler and has fewer moving parts.
Bring the stack up on the new VPS
Copy the project directories, Compose files, .env files, and volume archives to the new server. Restore each volume with the reverse of the backup command (create the named volume first with docker volume create), then start the stack.
# On the NEW server: restore one volume
docker volume create myapp_db_data
docker run --rm -v myapp_db_data:/data -v /root/migration/volumes:/backup
alpine tar xzf /backup/myapp_db_data.tar.gz -C /data
# Start the stack and watch the logs
docker compose up -d
docker compose logs -f --tail=100
Do not tear down the old stack yet. Run both in parallel. Hit the new server directly by IP or a temporary hosts entry and click through the important paths: login, uploads, background jobs. Check database row counts if you can. Only when the new stack behaves identically do you touch DNS.
Cut DNS over with the TTL trick
A docker compose migration goes smoothly when you shrink the TTL at least 24 hours before the cutover. Drop your A records to a TTL of 300 seconds a day ahead, make the switch, then raise it back once traffic has settled.
Order of operations: update DNS, wait a few minutes, confirm the new IP resolves from external resolvers (dig @8.8.8.8 and dig @1.1.1.1), then stop the old stack only after traffic has moved. During the overlap window both servers answer the same hostname, which is exactly what you want. If your app accepts writes, the old instance may still get stragglers for the length of the old TTL, so keep it running for at least double that before shutting it down.
Verify everything before you decommission the old VPS
Migration is not done when containers start. It is done when the service behaves correctly under the new IP. Check SSL certificates renewed correctly, scheduled cron jobs inside containers are firing, and external integrations (payment webhooks, email sending) still work, since some providers whitelist by IP. Look for these specifically:
- HTTPS certificate valid on the new IP with no mixed-content warnings
- Background workers processing the queue, not just the web container answering
- File uploads landing in the restored volume, not a fresh empty one
- Logs show no repeated connection errors to databases or caches
A mismatch between the Compose file’s bind-mount paths and the new server’s filesystem layout is the most common post-cutover failure. The paths on a fresh VPS are not always identical to the old one, so diff docker compose config output between the two servers.
Keep a docker rollback plan for at least a week
The old VPS is your insurance policy. Do not destroy it the day the migration “works.” Keep it stopped or running for seven days, and keep a snapshot if your provider offers them. A real docker rollback plan is three things: the old server still exists with data intact, you know the exact DNS change to reverse, and you have tested that the old stack still starts.
Before you declare victory, run one dry rollback: stop the new stack, point a test hostname back at the old server, confirm it serves, then switch back. Five minutes of testing now is worth more than a panicked hour later when something subtle breaks on day three. After the move, consider setting up automated backups; see my article comparing Duplicati, Restic, and Kopia for Docker volume backups for options.
Mistakes to avoid when moving Docker containers to a new VPS
Almost every failed Docker move falls into the same traps. The Compose file and images transferred fine, but the .env file was never copied, so secrets came up empty and the app boot-looped. Anonymous volumes with real data were left behind because nobody ran docker inspect. A database was backed up while the daemon was writing to it, producing a corrupt archive that restored without complaint and failed on first query.
The boring checklist prevents all of it: inventory everything, stop containers before volume backups, transfer .env and bind mounts, test the new stack on a temporary hostname, shrink the TTL before cutover, and keep the old server for a week. Migration day should feel anticlimactic. If it does, you did it right.