- Create a folder with name it as “docker-helloworld” in your host machine
- Create a file with name “helloworld.js” under “docker-helloworld” folder
- Add console.log statement with sample message in helloworld.js file
- Pull alpine node docker image into your host machine
- Write docker run command by setting following options
- set container name as "nodehelloworld"
- set container working directory i.e. /usr/app
- do bind-mount of “docker-helloworld” folder from host machine to container /usr/app folder
- run hello-world.js
Command:
> docker run
-w /usr/app
--mount type=bind,source=/c/Users/rama/docker-helloworld,target=/usr/app
--name nodehelloworld
mhart/alpine-node node helloworld.js
(or)
> docker run
-w //usr/app
--mount type=bind,source=$(pwd),target=/usr/app
--name nodehelloworld
mhart/alpine-node node helloworld.js
- -w --> used for setting container working directory
- --mount --> used for bindmount/volume
- --name --> used for specifying container name
- mhart/alpine-node --> alpine node image
- node helloworld.js --> run node command in the container
Happy Coding :)
No comments:
Post a Comment