← Back to all fixes

Data lost when container restarts

The Issue

Users upload files, container restarts, all uploads are gone.

Root Cause

Container filesystem is ephemeral. Anything written inside the container is lost when it is removed. You need a volume to persist data outside the container lifecycle.

How to Fix
  1. Mount a host directory: `docker run -v /host/uploads:/app/uploads myapp`
  2. Or use a named volume: `docker run -v myapp_uploads:/app/uploads myapp`
  3. List volumes: `docker volume ls`
  4. Inspect where data lives: `docker volume inspect myapp_uploads`
  5. In Compose, define volumes under the service and the top-level `volumes:` key