-
Create a folder "docker-node"
-
Change directory
cd docker-node
-
Open VS code here:
code .
-
Inside VS code:
- Open terminal
npm init
creates package.jsonnpm i express
install express and node module gets created.- create "main.js" and write the required code.
-
Create a configuration file for image called
Dockerfile
and write required code -
convert into image:
- syntax : docker build -t(tag) imageKaNaam Dockerfile_ka_path
docker build -t mera-nodejs-image .
-
Run Image inside container
docker run -it imageName
- it will create the container but data will not be visible through browser
- now you need to map the container port to local machine port, so that it can be accessible through the browser
docker run -it -p 8000:8000 imageName
-
docker exec -it containerId bash
- opens a new bash terminal inside the container whose id is specified in the command.
-
ls
- list all available files in the container.
-
cat main.js
- cat show the content of main.js in the command line.