VPS Tutorials
Data missing after a Docker Compose rebuild: find and reconnect storage
If a rebuilt container shows an empty site, inspect the Docker host, project name and actual mounts. Locate the old volume, back it up and distinguish a wrong mount from deleted data.

After a Docker Compose update, your site returns to its installation screen and accounts, posts or uploads appear to be missing. Do not initialize it again yet. The new container may have mounted a different, empty volume while the original data remains on the VPS.
For a single Docker Engine host, work through four stages: confirm the daemon, inspect the actual mount, identify the original storage, then back up and reconnect it. This can locate a wrong mount; it cannot guarantee recovery of deleted volumes or corrupted databases. Replace every example project, service and volume name with the real one before operating.
Pause uploads, registration and background jobs. Preserve both instances and their configurations. If you are unsure which service owns the data, investigate before scheduling downtime; deleting a container is not a useful diagnostic experiment. Avoid docker compose down -v, docker volume rm and all volume-cleanup commands for now.
The Compose down reference distinguishes the operations: ordinary down removes containers and networks while retaining named volumes by default. Adding -v removes declared named volumes and attached anonymous volumes, except external volumes. Even when an anonymous volume survives, a later up does not automatically reconnect it.
| Symptom | Check first | Possible next step |
|---|---|---|
| A new installation after moving directories | Compose project and volume names | Locate the old project's volume |
| A suddenly empty file directory | Actual bind-mount Source | Reconnect the original absolute path |
| A new database after an upgrade | Data path, image version and database address | Compare version guidance and the original database |
| A volume-deletion command was run | Remaining volumes, backups and disk snapshots | Restore a backup or stop disk writes and seek recovery help |
From the original deployment directory, use the same -p, -f and --env-file as the deployment script or control panel. Here shop is only an example project name:
docker context show
docker info --format '{{.Name}}'
docker compose ls -a
docker compose -p shop -f compose.yaml ps -a
docker compose -p shop -f compose.yaml config
Your workstation, a remote Docker context, rootless Docker and the system daemon can each have separate storage. Confirm the connection before concluding that an empty volume list means deletion. config expands environment variables: inspect the database address and database name, but do not publish output containing passwords.
An application connected to a different database can look empty even when its volume is correct. Continue with diagnosing Compose environment-variable changes if the configuration source is uncertain.
Copy the real container name from ps -a or your panel and inspect .Mounts:
docker inspect shop-app-1 --format '{{json .Mounts}}'
docker volume ls
docker volume inspect shop_data
docker ps -a --filter volume=shop_data
Compare four fields with the old container, original configuration and image documentation: whether Type is volume or bind; the actual volume Name; its Source; and the container path Destination. Creation times and Compose labels are clues, but similar names alone do not establish ownership.
Data written only to a container's writable layer is lost when that container is removed during recreation. If the original container still exists, preserve it and arrange a consistent backup before extracting data. Never run multiple database instances against the same data directory.
Under the project-name precedence rules, -p overrides COMPOSE_PROJECT_NAME, followed by top-level name, then directory-derived defaults. Looking at the current directory name alone is insufficient.
The following is a standalone configuration demonstration, not a production recovery file. BusyBox is a placeholder, and /data is a demonstration directory:
services:
app:
image: busybox:1.37
command: ["sleep", "86400"]
volumes:
- data:/data
volumes:
data: {}
With project shop, the default volume name is shop_data. Changing the project to shopnew makes it shopnew_data. Both files can declare data while referring to different real volumes; the new empty one may trigger initialization.
After identifying the original volume, retain the original image, environment and container data path in the production configuration, changing only the relevant volume declaration:
volumes:
data:
external: true
name: shop_data
The volume name and external documentation explains that name uses the exact volume name without a project prefix. external: true requires that volume to exist: startup fails if it is missing instead of creating an empty replacement. Neither setting verifies the contents or provides a backup.
Make a recoverable backup before changing anything. Stop every old instance that can write to that volume, review the final config, then start the original application during a maintenance window. Use a database version compatible with the original files. Recovery is not the time for a major upgrade, and the BusyBox example must not replace your production service.
Moving the project from /opt/shop to /opt/shop-new can change what ./data points to. For multiple Compose files, also check the base file's directory. The container's inspected Source is the final evidence.
The bind-mount reference notes that mounting over a container path hides the files already there. Some short-syntax forms also create an empty source directory if it is missing. An empty mounted directory does not establish that the old directory was deleted.
This is another independent demonstration. An absolute path is easier to audit, and create_host_path: false makes startup fail if the source is absent:
services:
app:
image: busybox:1.37
command: ["sleep", "86400"]
volumes:
- type: bind
source: /srv/shop-data
target: /data
bind:
create_host_path: false
Check that the old path exists and its dates and size match expectations. Do not copy an empty directory over it or apply broad chmod 777 changes. If an upgrade changed the image's data path, consult its migration notes; the PostgreSQL 18 deployment guide covers its particular volume-path change.
Before reconnecting storage, establish that it contains the original business data, no other instance is writing to it, the image accepts its format, and the backup restores in an isolated environment. Archiving a running database directory casually does not guarantee consistency. Use the database's native backup method or a documented stopped backup; see backup and restore drills.
After recovery, verify old accounts, several historical records, uploads and background jobs, then test a new write and read. If the empty installation already accepted new orders or files, preserve that data and plan a merge before replacing it.
If the original volume is absent on the correct daemon, or data existed only in the writable layer of a removed container, check offsite backups, database backups and disk snapshots. Without a backup, minimize writes to the source disk and assess professional recovery. Creating a new volume with the same name does not recover the previous contents.
The original article's verification was limited to static Compose parsing: volume names under two project names, a fixed external-volume reference, and disabling automatic directory creation for a bind mount. It did not perform real volume remounts, start a restored database or test data recovery.