Saturday, April 18, 2020

Docker Assignments #6: Docker, Node and helloworld.js

  1. Create a folder with name it as “docker-helloworld” in your host machine
  2. Create a file with name “helloworld.js”  under “docker-helloworld” folder
  3. Add console.log statement with sample message in helloworld.js file
  4. Pull alpine node docker image into your host machine
  5. 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
      6. Check console.log message on the terminal

 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