docker volume create testvolume
docker volume ls
Here we are are attaching volume testvolume
with a folder named app
using nginx:latest image
docker run -d --name voldemo -v testvolume:/app nginx:latest
docker exec -it voldemo bash
apt update
apt install nano
cd app
nano test.txt
Once the nano editor opens up, add the below content or whatever you want
Hello World! Welcome to the test file!!
Now save the file using ctrl+x
then press y
and Enter
docker stop voldemo
docker rm voldemo
docker run -d --name voldemo -v testvolume:/app nginx:latest
Again, check if the data still exists or not
docker exec -it voldemo bash
ls
cd app
cat test.txt