basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    The stack directory is the compose project name and the volume prefix

    Before moving or renaming a stack directory, pin the project name or the volume names. Otherwise compose creates new empty volumes, and the data stays in the old ones.

    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/app2 compose created a new empty app2_data, while the data stayed in app_data.
    Fix
    Pin the old name — name: app in compose or name: app_data on the volume — and run up -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.