DockerFile Node App

Node Sample application

$ mkdir node 
$ cd node
$ apt install npm && npm init -y
$ npm install ronin-server ronin-mocks
$ vi server.jsconst ronin = require('ronin-server')
const mocks = require('ronin-mocks')

const server = ronin.server()

server.use('/', mocks.server(server.Router(), false, true))
server.start()

Test the application

$ node server.js
$  curl --request POST \
--url http://localhost:8000/test \
--header 'content-type: application/json' \
--data '{"msg": "testing" }'
# syntax=docker/dockerfile:1# Base Image of node 
FROM node:12.18.1
#Set ENV veriable
ENV NODE_ENV=production

#Set working Directory
WORKDIR /app
# Copy the necessy packages
COPY ["package.json", "package-lock.json*", "./"]
#Run the npm commands
RUN npm install --production
# Copy everything in current /app directory
COPY . .
# Strat the node application
CMD [ "node", "server.js" ]
$ docker build -t node-docker:v1.0.0 . 
$ docker run -d -p 80:8000 --name node-app node-docker:v1.0.0

Cloud and DevOps Enthusiast