← 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
Mount a host directory: `docker run -v /host/uploads:/app/uploads myapp`Or use a named volume: `docker run -v myapp_uploads:/app/uploads myapp`List volumes: `docker volume ls`Inspect where data lives: `docker volume inspect myapp_uploads`In Compose, define volumes under the service and the top-level `volumes:` key