Why does my non-volume data in Docker container persist even after restarting the container?
The data is lost when the container is removed, not when it's stopped or restarted.
Basically, if you do docker ps
, if the containers keeps the same id (the big ugly hexadecimal id), the data is not lost.
It gets complicated when somehow your docker containers are not managed by you, but by some kind of automated-managing method. Tools like these usually start new containers if there is failure. In that case you should mount a volume to store your data on the host.
You might want to look at the Container Lifecycle: https://github.com/wsargent/docker-cheat-sheet#lifecycle
docker create
creates a container but does not start it.
docker rename
allows the container to be renamed.
docker run
creates and starts a container in one operation.
docker rm
deletes a container.
docker update
updates a container's resource limits.
If you do docker rm
and docker run
again your state will not be there anymore.
If you want a transient container,
docker run --rm
will remove the container after it stops.