Sikau

Project: Laptop to production · Day 3 · about 40 min

A production Dockerfile

Cache-friendly layers, no secrets, a non-root user, a version and a health check.

Build once, run anywhere

Package the café API so it runs the same everywhere: small, fast to rebuild, without the laptop's .env or node_modules, not as root, stamped with its version, and able to report its own health.

Dockerfile

FROM node:20-alpine
ARG VERSION=dev
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
ENV NODE_ENV=production APP_VERSION=$VERSION
USER node
EXPOSE 3000
HEALTHCHECK CMD wget -qO- http://localhost:3000/health || exit 1
CMD ["node", "server.js"]

The rest of this lesson

  • Stamping the versionexplain
  • Checking the imageexplain
  • What rebuilds?predict
  • Dockerfile line, purposematch
  • Write the Dockerfilewrite code
  • Badge quizquiz
  • What you builtrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 4 lessons of Project: Laptop to production