How to RUN a NodeJS application in Docker

Dockerfile

FROM node:14-alpine3.15 

WORKDIR /app

RUN chown -R node /app

USER root

COPY package.json .

RUN npm install 

COPY . . 

EXPOSE 8080 

CMD [ "node", "server.js" ]

Server.js

const express = require('express');

const app = new express(); 

const port = process.env.PORT || 8080 ; 

app.get('/', (req, res)=>{
    res.send('AWS With Atiq');
});

app.listen(port, ()=>{
    console.log('app started');
})

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

Leave a Reply