Skip to content

Instantly share code, notes, and snippets.

@dweidner
Last active March 6, 2024 13:48
Show Gist options
  • Save dweidner/4dc038da8ba946a534ae2ee813a3df5e to your computer and use it in GitHub Desktop.
Save dweidner/4dc038da8ba946a534ae2ee813a3df5e to your computer and use it in GitHub Desktop.
Docker-based Node development environment
node_modules/
.dockerignore
.git
.gitignore
.npmrc
.env*
!.env.example
npm-debug.log
name: "example"
services:
node:
build:
context: "."
args:
- "NODE_VERSION=${NODE_VERSION:-20.11}"
- "NODE_ENV=${NODE_ENV:-production}"
- "UID=${UID:-1000}"
- "GID=${GID:-1000}"
command: "npm start"
restart: "unless-stopped"
tty: true
init: true
env_file:
- path: ".env"
required: false
ports:
- "${FORWARD_APP_PORT:-8080}:8080"
volumes:
- ".:/app"
- "/app/node_modules"
# syntax=docker/dockerfile:1.4
ARG DEBIAN_RELEASE="bookworm"
ARG NODE_VERSION="20.11"
FROM node:${NODE_VERSION}-${DEBIAN_RELEASE}-slim
LABEL maintainer="Daniel Weidner <hallo@danielweidner.de>"
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.name="node"
LABEL org.label-schema.description="Example Dockerfile for a node development environment"
LABEL org.label-schema.docker.cmd="docker run -d -v .:/app -v /app/node_modules node npm start"
ARG NODE_VERSION
ARG NODE_ENV="production"
ARG UID=1000
ARG GID=1000
ENV NODE_VERSION="${NODE_VERSION}"
ENV NODE_ENV="${NODE_ENV}"
RUN <<-EOR
set -e
apt-get update
apt-get install --yes --no-install-recommends build-essential=12.9
apt-get clean
rm -rf /var/lib/apt/lists/* use/share/doc /usr/share/man
groupmod -g "${GID}" node
usermod -u "${UID}" -g "${GID}" node
EOR
USER node
WORKDIR /app
COPY --link --chown=node:node package*.json ./
RUN <<-EOR
set -e
npm clean-install --include=dev
npm cache clean --force
EOR
CMD ["node"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment