Which statement best describes why data stored inside a Docker container's filesystem is lost after the container stops?
Think about what happens when you stop and start a container without volumes.
Docker containers use a layered filesystem that resets to the original image state when restarted unless volumes are used. This means any changes made inside the container's filesystem are lost after it stops.
What will be the output of the following commands executed on a Docker container?
docker run --rm ubuntu sh -c "echo hello > /tmp/greeting.txt && cat /tmp/greeting.txt" docker run --rm ubuntu cat /tmp/greeting.txt
Assuming no volumes are used.
Consider what happens to files created inside a container after it exits.
The first command creates a file and outputs 'hello'. The container is removed after running. The second command starts a new container with a fresh filesystem, so the file does not exist and cat returns an error.
You want to keep data created by a container even after it stops. Which Docker command option should you use to achieve this?
Think about how to store data outside the container's ephemeral filesystem.
Mounting a host directory as a volume with -v allows data to persist on the host filesystem, surviving container restarts and removals.
You mounted a volume to persist data, but after restarting the container, the data is missing. What is the most likely cause?
Check the paths used in the volume mount.
If the volume is mounted to the wrong path inside the container, data written elsewhere will not be saved to the volume, causing apparent data loss.
Which practice best ensures that important application data is not lost when containers are updated or recreated?
Think about separating data from container lifecycle.
Using volumes or bind mounts stores data on the host or external storage, independent of container lifecycle, ensuring durability across updates and recreations.