How does persistence work in Docker?
First lets demonstrate how containers are stateless:
docker run -it busybox
echo 'some text' > file.txt'
cat file.txt
exit
docker run -it busybox
cat file.txt
Docker Volumes
-
Native to Docker
-
Managed by the CLI
-
Can be shared between containers
docker volume create files
docker volume inspect files
docker run -it -v files:/test busybox
cd test
echo 'some text' > file.txt
cat file.txt
exit
docker run -it -v files:/test busybox
cd test
cat file.txt