How to Migrate a Docker Compose Stack to a New Server

Moving a Docker Compose-based application to a new VPS — whether for an upgrade, provider switch, or scaling need — follows a fairly systematic process when approached carefully.

Step 1 — Document Your Current Stack

docker compose config

Review the fully-resolved configuration, including any environment variable substitutions, so you understand exactly what's actually running before migrating.

Step 2 — Back Up All Volume Data

docker run --rm -v myapp_postgres-data:/data -v $(pwd):/backup alpine tar czf /backup/postgres-data.tar.gz /data

Repeat for each named volume in your stack — this is your actual application data and must be transferred correctly.

Step 3 — Transfer Backup Archives to the New Server

scp *.tar.gz newuser@NEW_SERVER_IP:/home/newuser/

Step 4 — Set Up Docker on the New Server

See How to Install Docker Engine on Ubuntu & Debian (Complete Guide) and How to Install Docker Compose on Ubuntu & Debian.

Step 5 — Transfer Your Compose Files and Configuration

scp docker-compose.yml .env newuser@NEW_SERVER_IP:/home/newuser/myapp/

Step 6 — Recreate Volumes and Restore Data on the New Server

docker volume create myapp_postgres-data
docker run --rm -v myapp_postgres-data:/data -v $(pwd):/backup alpine tar xzf /backup/postgres-data.tar.gz -C /

Step 7 — Start the Stack on the New Server

docker compose up -d

Step 8 — Verify Everything Started Correctly

docker compose ps
docker compose logs

Confirm all services are running and healthy (see How to Set Up Health Checks for Docker Compose Services) before proceeding.

Step 9 — Verify Data Integrity

Check that migrated data is actually present and correct — spot-check database records, verify file uploads are accessible, confirm application functionality end-to-end before considering migration complete.

Step 10 — Update DNS to Point to the New Server

See How to Point a Domain to Your VPS (A/AAAA Records) and Understanding DNS Propagation and TTL — lower TTL in advance of the migration if minimizing cutover disruption matters.

Step 11 — Keep the Old Server Running Briefly as a Fallback

Don't immediately decommission the old server — keep it available (stopped or running) for a reasonable period in case you discover an issue with the migration and need to quickly revert DNS back.

Minimizing Downtime: A More Advanced Approach

For genuinely minimal-downtime migration, consider setting up the new server fully in advance, syncing data close to cutover time (rather than a single full backup/restore), and switching over with only a brief final sync gap — more complex, but reduces the actual downtime window significantly for production-critical applications.

Common Errors

Application starts but shows no data — verify volume names match exactly between the backup/restore process and what the compose file actually expects; a volume naming mismatch is a common migration mistake.

Continue Reading

Browse more articles in Docker & Containers.

  • migrate docker compose, docker stack migration, move docker to new server, docker volume backup restore
  • 0 användare blev hjälpta av detta svar
Hjälpte svaret dig?

Relaterade artiklar

How to Install Docker Engine on Ubuntu & Debian (Complete Guide)

Docker lets you package applications and their dependencies into lightweight, isolated containers...

How to Install Docker Compose on Ubuntu & Debian

Docker Compose lets you define and run multi-container applications from a single YAML file,...

Deploy Your First Docker Container: A Beginner's Walkthrough

With Docker installed, this hands-on walkthrough covers the core workflow you'll use constantly:...

How to Update Docker and Docker Compose Safely

Keeping Docker Engine and Compose updated brings security fixes, performance improvements, and...

Docker Compose Troubleshooting: Common Errors & Fixes

A reference guide to the Docker and Docker Compose errors you're most likely to encounter, with...