Docker Ep 16: Named Volumes

Docker Volume Commands:

  1. Helper volume commands:
docker volume --help 
docker volume ls
docker volume prune
docker rm <volume-name-or-id>

Introduction to Docker Named Volume:

docker volume ls
Deleting Anonymous Volume Container = Deleting Volume created with it = Data loss

Dockerizing Node.js App with Named Volume:

VOLUME ["app/feedback"]   // Remove this line - used by Anonymous Volume
docker rmi <image-name:tag>
eg. docker rmi feedback-node:volumes
docker build -t <image-name>:<tag> .
eg. docker build -t feedback-node:volumes .
-v <volume-name>:<volume-path> // ADDITIONAL FLAG  docker run -d -p 3000:80 --rm --name <container-name> -v <volume-name>:<volume-path>  <image-name>eg. docker run -d -p 3000:80 --rm --name feedback-app -v feedback-may2022:/app/feedback feedback-node:volumes
docker volume ls
http://localhost:3000/
http://localhost:3000/feedback/awesome.txt
docker stop <container-name>
i.e. docker stop feeback-app
-v <volume-name>:<volume-path> // ADDITIONAL FLAGdocker run -d -p 3000:80 --rm --name <container-name> -v <volume-name>:<volume-path>  <image-name>eg. docker run -d -p 3000:80 --rm --name feedback-app -v feedback-may2022:/app/feedback feedback-node:volumes
http://localhost:3000/feedback/awesome.txt

Video:

Closing Thoughts:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store