Last active
March 6, 2024 13:48
-
-
Save dweidner/4dc038da8ba946a534ae2ee813a3df5e to your computer and use it in GitHub Desktop.
Docker-based Node development environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules/ | |
.dockerignore | |
.git | |
.gitignore | |
.npmrc | |
.env* | |
!.env.example | |
npm-debug.log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 <[email protected]>" | |
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