You stop a container to change a setting. You start it again. Everything is gone — the database rows, the uploaded files, the configuration you spent an hour on. Nothing was corrupted and nothing failed. The system did exactly what it was designed to do, which is the least satisfying explanation possible until you understand the https://saborcitosrestaurant.com/ design.
The writable layer is disposable by design
A running container gets a writable layer stacked on top of its image’s read-only layers. Everything the container writes lands there. That layer is tied to the container’s lifecycle: destroy the container and the writable layer is destroyed with it.
This is not an oversight. It is the property that makes containers replaceable. You can rebuild an image, roll out a new version, and throw away the old instance without accumulating drift, precisely because the instance carries no state worth keeping. For a stateless web frontend, this is exactly right.
Real applications, however, are rarely fully stateless. A database that forgets its rows on restart is not a database. So the question is not how to stop the writable layer from being disposable, but how to keep the data that matters out of it.
Volumes: storage with a different lifecycle
A volume’s contents exist outside the lifecycle of any given container. When the container is destroyed, the writable layer goes with it — but the volume persists. It remains available to Docker even when no running container is using it, and it is not removed automatically.
Volumes are managed by Docker itself and stored in a directory the daemon controls. Because a volume does not live inside the container, it does not increase the size of containers using it. And because writes go directly to the host filesystem rather than through the union filesystem’s storage driver, volumes are typically faster than writing into the container layer.
A single volume can also be mounted into multiple containers at once, which is what makes patterns like a backup sidecar reading the same data possible.
One behaviour worth knowing in advance
If you mount a volume into a container directory that already contains files, the pre-existing files are obscured by the mount. They are not deleted, but they become invisible while the mount is in place. This catches people out when an image ships default configuration in a directory they then mount over.
The rule that prevents most of this
Decide, before you start a container, which of its directories hold data you would be upset to lose. Mount those. Everything else can live in the writable layer and be thrown away, which is what it is for. The failure mode is almost never that volumes are complicated — it is that nobody asked the question until after the data was gone.