How to Move Docker Compose and Volumes to a New VPS
By Small Corner Labs · · 3 min read
Copying compose.yaml recreates the service definitions. To move the running application, also preserve the data its containers mount, the configuration they need and the database state. Restore those on the new VPS before routing traffic.
Which files and volumes should you copy?
Bring compose.yaml, any override files, build context, and the environment files or secrets needed to start the services. Keep secrets in a protected transfer path. Use docker compose config --volumes to list declared volumes and inspect the running containers for their actual mounts. The top-level Compose project name can affect the real name of a volume.
In this example, uploads is a Docker-managed named volume. The config file is a bind mount relative to the Compose file. The example uses an existing image placeholder. Copy the content of uploads and the actual config file as separate items.
services:
app:
image: your-app-image:1.0
volumes:
- uploads:/app/uploads
- ./config/app.conf:/app/app.conf:ro
volumes:
uploads:How do you back up and restore a Docker volume?
For an uploads volume, pause the services that write to it and create an archive from a helper container with the volume mounted read-only. Restore into the named volume the destination stack will mount, and check file ownership and a sample checksum before starting the app. Copy each bind mount to its expected host path with the ownership and permissions the container needs.
If PostgreSQL or MySQL uses a volume, prefer a database-native backup and a test restore into a compatible database. A file-level copy requires a consistent snapshot or a clean shutdown. Schedule the last database export or file copy after pausing writes so new records are included.
How do you verify the Compose stack before cutover?
On the destination, validate the Compose config and check image versions, port bindings and mount names. Start the stack in an isolated environment. Check docker compose ps, read the logs, fetch a known uploaded file and query a recently created database record. Keep workers that send email or run scheduled jobs paused until the destination owns production.
Quick checklist
- Record Compose services and actual mount names.
- Archive file volumes and make a consistent database backup.
- Restore data and verify names, ownership and application reads.
- Pause source writes before the final sync.
Frequently asked questions
Why does my Docker volume look empty after moving the Compose project?
A different Compose project name can make Docker attach a new volume. Inspect the destination container mounts and compare the actual volume name with the volume you restored. If they differ, stop writers and point the project at the restored volume before restarting.
Does restoring a named volume also restore a bind mount?
A bind mount points to a path on the host. Copy the original host files separately and confirm that the path in compose.yaml resolves correctly on the new VPS. Relative paths depend on the Compose file location.
