Skip to content

Instantly share code, notes, and snippets.

@lahin31
Created September 24, 2022 17:59
Show Gist options
  • Save lahin31/01c51bdcb6029f564f8f34f7ba225c14 to your computer and use it in GitHub Desktop.
Save lahin31/01c51bdcb6029f564f8f34f7ba225c14 to your computer and use it in GitHub Desktop.
Node.js with Docker Compose
.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 and Run with Docker Compose

docker compose up
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'));
version: "3.9"
services:
node-app:
build:
context: ./
ports:
- "2000:2000"
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
environment:
- NODE_ENV=development
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 i
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