Skip to content

Instantly share code, notes, and snippets.

@edsonmgoz
Created February 20, 2026 01:49
Show Gist options
  • Select an option

  • Save edsonmgoz/b4f9f1dac43c5cffb7aa1179320b2146 to your computer and use it in GitHub Desktop.

Select an option

Save edsonmgoz/b4f9f1dac43c5cffb7aa1179320b2146 to your computer and use it in GitHub Desktop.
Hello World NodeJS example using Multi-Stage
# Stage 1: build
FROM node:18-slim AS build
WORKDIR /app
# Copiar dependencias
COPY package*.json ./
RUN npm install
# Copiamos el código (puede ser directamente COPY . .)
COPY app.js ./
# Stage 2: runtime
FROM node:18-slim AS runtime
WORKDIR /app
# Crear usuario/grupo NO ROOT
RUN groupadd --gid 10001 appgroup \
&& useradd --uid 10001 --gid 10001 --create-home --home-dir /home/app appuser
# Copiar código fuente (SOLO lo necesario) desde build
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/package*.json ./
COPY --from=build /app/app.js ./
# Permisos y ejecución como usuario NO ROOT
RUN chown -R appuser:appgroup /app
USER appuser
EXPOSE 3000
CMD ["node", "app.js"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment