What if all your work vanished every time you closed your app? Containers do that by default!
Why Container filesystem is ephemeral in Docker? - Purpose & Use Cases
Imagine you run a software inside a container and make some changes to files while it's running. Then, you stop the container and start it again later. You expect your changes to still be there, but they are gone!
Manually managing file changes inside containers is frustrating because containers don't save changes after they stop. This means you lose work, have to redo setups, and can't keep important data easily.
Understanding that the container filesystem is ephemeral helps you plan better. You can use special storage areas called volumes to keep data safe outside the container's temporary space.
docker run myapp # make file changes inside container # stop container # start container again # changes lost
docker run -v mydata:/app/data myapp # changes saved in volume # stop and start container # changes persist
This concept lets you keep important data safe and share it between containers, making your apps reliable and easy to manage.
A developer runs a database inside a container. Without volumes, all data disappears when the container stops. Using volumes, the database keeps all records safe even after restarts.
Containers erase file changes when stopped.
Data must be stored outside containers to persist.
Volumes solve the problem by saving data safely.