Docker container gets a temperary memory if we make a database inside the container and write it when the container gets deleted the database and the data also get deleted
docker volumes are a kind of permanent storage which you can bind with your container making it a permanent storage for your container
- make a app folder with index.js file having the following code
console.log("Hello World from nikhil") - open terminal pull a node image
docker run -it node:latest
docker container ls -a ## a stands for all
- Let's moun the app folder to node container
docker run -it -v [Location of app]:/home/app node bashIf you are in windows use this commanddocker run -it -v %cd%/dockerVolume:/home/app node bashcd = current directory for windows like pwd cwd %cd% it will treated as variable A bash will open do
uname whoami ls [separately]
To see the code inside the index.js
cat index.js
- Let's install the nodemon to check whether the folder is mounted properly or not and also syncing with the container or not
npm i -g nodemon
nodemon index.js
now make changes in index.js it should reflect in the node container
docker volume create data
docker volume ls
docker volume rm data
docker run -it -v data:/data node bash
let's make a directory inside the volume
cd data
mkdir nikhil-dubey
open new terminal and mount volume data to ubuntu image
docker run -it -v data:/myapp ubuntu bash
- The data directory is mounted to myapp folder go inside it
- do ls you will see the nikhil-dubey folder
- make a new directory nikhild
- Go inside the node container you will see the nikhild inside the data folder