I've a basic counter application in javascript.
var count=0;function counter(){ count++; console.log(count);}counter();
I want to test persistence of data using volumes and bind mount in docker.
How do I do it?
I'm aware of syntax for volumes, but I didn't get exactly what I should do here.
What I've tried?
Create a Dockerfile
COPY index.html /usr/share/nginx/htmlCOPY script.js /usr/share/nginx/html
Build the image using
docker build -t my-counter-app .
Image named my-counter-app has been built.
Start and Run the container using volumes
docker run -it -d -p 80:80 -v demo_volume:/data my-counter-app
Stop and remove the container
docker stop <container-id>
docker rm <container-id>
Again start and run the container
docker run -it -d -p 80:80 -v demo_volume:/data my-counter-app
My expected output is that the counter should begin with last recorded value.
How do I achieve this? I don't want to use docker compose or any additional things.