-
Create the Node.js app
-
Create a Dockerfile
- FROM node:carbon
- WORKDIR /usr/src/app
- COPY package*.json ./
- RUN npm install
- COPY . .
- CMD [ "npm", "start" ]
-
Create .dockerignore file
-
Build docker image
- docker build -t <your username>/node-web-app
-
Run the image
- docker run -p public:private -d <your username>/node-web-app
- docker ps
- docker logs <container id>
- docker exec -it <container id> /bin/bash
-
Test
Referenced this article: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/