- Beginner
- Containers and images
How it works
The image layers stay read-only. When a container modifies a file of the image, the file is first copied up into its writable layer (copy-on-write), so other containers of the same image keep seeing the original.
What breaks
Data written there, a database or uploaded files, is lost by docker rm, by docker compose down or when a container is recreated for an upgrade. The layer also grows silently on the server's disk. Anything that must outlive the container goes in a volume.
In a terminal
docker run -d --name web nginx:1.27
docker exec web sh -c 'echo hello > /usr/share/nginx/html/note.txt'
docker rm -f web
docker run -d --name web nginx:1.27
docker exec web cat /usr/share/nginx/html/note.txt
See it break, then fix it
Write the Dockerfile or the compose file, type the docker commands, and watch a simulated server run them through reboots, upgrades and traffic. Free to start.