Skip to content

Instantly share code, notes, and snippets.

@lahin31
Last active September 24, 2022 16:35
Show Gist options
  • Save lahin31/1385607224ef009129b8776c3f177705 to your computer and use it in GitHub Desktop.
Save lahin31/1385607224ef009129b8776c3f177705 to your computer and use it in GitHub Desktop.
Node.js with Docker
.dockerignore
.env
.git
.gitignore
.vs
.vscode
*.dbmdl
*.jfm
azds.yaml
charts
docker-compose*
Dockerfile*
node_modules
npm-debug.log
secrets.dev.yaml
values.dev.yaml
README.md

Build the Image

docker build -t nodejs-docker . 

Run the Container

docker run -p 2000:2000 -v $PWD:/usr/src/app -v /usr/src/app/node_modules nodejs-docker
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('This is Home you know');
});
app.listen(2000, () => console.log('Server started'))
FROM node:14.18.0-alpine AS builder
ARG PORT=2000
ENV PORT=${PORT}
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json ./
COPY package-lock.json ./
# Install dependencies for the app
RUN npm install
EXPOSE $PORT
CMD [ "yarn", "start:dev" ]
{
"name": "nodejs-docker",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node app.js",
"start:dev": "nodemon app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.1"
},
"devDependencies": {
"nodemon": "^2.0.20"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment