Sikau

DevOps and deployment · Day 2 · about 30 min

Your first Dockerfile

FROM, WORKDIR, COPY, RUN, CMD — build and run the café API.

Write the recipe

A Dockerfile lists the steps to build your image: start from a base image, copy your code, install dependencies, and say which command starts the app.

Dockerfile instructions

FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
ENV NODE_ENV=production
EXPOSE 3000
CMD ["node", "server.js"]

docker build -t name:tag . — the . is the build context: the folder Docker can COPY from.

The rest of this lesson

  • Each instruction's jobexplain
  • Build, tag, runexplain
  • Build or run?predict
  • When does it happen?match
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 14 lessons of DevOps and deployment