Card 02/ 05
All 5 cards
ExampleDifficulty: Beginner1 min
A File That Does Not Survive `docker rm`
Write a file inside a container, stop it, start it again, and the file is still there. Remove the container and it never existed.
$ docker run -d --name box alpine sleep 600
$ docker exec box sh -c 'echo important > /data.txt'
$ docker exec box cat /data.txt
importantStopping and starting keeps it, because stopping ends the process and leaves the container.
$ docker restart box
$ docker exec box cat /data.txt
importantRemoving the container is what takes the layer with it.
$ docker rm -f box
$ docker run --rm alpine cat /data.txt
cat: can't open '/data.txt': No such file or directoryThe second container came from the same image and saw the image only. --rm on that last command is the same rule stated in advance: remove the container as soon as it exits.