Skip to content
docktionary

Snippets / Dockerfile

Node.js app

A single-stage Dockerfile for an Express/Node HTTP service.

nodejavascriptsingle-stage
Dockerfile
FROM node:22-alpine
WORKDIR /app

# Install deps in their own layer first -- this only re-runs when the
# lockfile changes, not on every source edit.
COPY package.json package-lock.json ./
RUN npm ci --omit=dev

COPY . .

ENV NODE_ENV=production
EXPOSE 3000
# The node:* images ship a non-root "node" user already -- no need to
# create one yourself.
USER node

HEALTHCHECK --interval=30s --timeout=3s CMD wget -qO- http://localhost:3000/health || exit 1

CMD ["node", "server.js"]