Where the empty volumes come from
By default a compose project is named after its directory, and volumes are <project>_<volume>. Move /opt/app
to /opt/app2 and compose creates new empty volumes app2_data, and the data “disappears”: it stays in
app_data, but the container can’t see it.
Pin the project or volume name:
name: app # project name — no longer depends on the directory
volumes:
data:
name: app_data # or an explicit volume name
If it doesn’t work
Moved the stack directory — the app started with an empty database
- Cause
- A compose project is named after its directory, and its volumes are
<project>_<volume>. In/opt/app2compose created a new emptyapp2_data, while the data stayed inapp_data. - Fix
- Pin the old name —
name: appin compose orname: app_dataon the volume — and runup -d.
How to check
Run docker volume ls before and after the move: no empty twins should show up in the list. docker compose config
shows the final names before you start anything.