You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Running pre-built images is useful, but the real power of Docker comes from building your own images. This lesson covers Dockerfile syntax, key instructions, build context, layer caching, .dockerignore, and multi-stage builds.
A Dockerfile is a plain text file containing a series of instructions that Docker uses to assemble an image. Each instruction creates a layer in the image.
# Simple Dockerfile example
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]
Every Dockerfile must start with FROM. This sets the base image that your image builds upon.
# Official Node.js image based on Alpine Linux (small)
FROM node:20-alpine
# Official Python image
FROM python:3.12-slim
# Minimal base — just a shell
FROM alpine:3.19
# Empty base — for fully static binaries
FROM scratch
Tip: Always use specific tags (e.g.
node:20-alpine) rather thanlatestto ensure reproducible builds.
RUN executes a command during the build and commits the result as a new layer.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.