DevOps Peach

Docker & Kubernetes · Module 02

Building Docker Images with Dockerfile

Write Dockerfiles, understand layers and the build cache, use CMD/ENTRYPOINT correctly and keep production images small with multi-stage builds.

Practice interactively →

What you will learn

Lessons

  1. Dockerfile and image layers

    A Dockerfile is the recipe for an image; every instruction that changes the filesystem adds a layer on top of the base image.

  2. The main Dockerfile instructions

    FROM, RUN, WORKDIR, COPY, EXPOSE, ENV and ARG — what each instruction does and the usual traps.

  3. CMD and ENTRYPOINT

    ENTRYPOINT is the main program, CMD holds the default arguments; arguments after the image name replace CMD, not ENTRYPOINT.

  4. Multi-stage builds and the build cache

    Split the build stage from the production stage so the final image only holds the artifact; order instructions to use the cache.