To create a tiny node J.S. web application, wrap it inside of a docker container and then be able to access that web application from a browser running on your local machine.
- Create Node JS Web App
- Create a Dockerfile
- Build image from Dockerfile
- Run image as Container
- Connect to web app from browser
1. Create Node JS App
- First create package.json and index.js
- To install the node dependencies, run
npm install
- To start the server, run
npm start
ornode index.js
2. Create a Dockerfile
- Template
- Specify Base Image:
FROM alpine
- Run some commands to install additional programs:
RUN npm install
- Specify a command to run on container startup:
CMD ["npm","start"]
- Specify Base Image:
3. Build image from Dockerfile
- To build the image, use
docker build .
4. Run image as Container
docker run vidya25/simpleweb
5. Connect to web app from browser
- Port Mapping:
docker run -p 8080:8080 vidya25/simpleweb