Hands-On LabBeginner

Write Dockerfiles and Build Custom Images

Author a single-stage Dockerfile from scratch, build a tagged image for a static site, and observe layer caching in action.

60 minEstimated time
4Guided steps
AutoVerification
IsolatedSandbox
Write Dockerfiles and Build Custom Images

Lab overview

A Dockerfile is a plain-text recipe that tells Docker how to assemble a container image, instruction by instruction. Each line (FROM, COPY, RUN, and CMD) becomes a stacked, content-addressed layer, and Docker's build engine BuildKit reuses any layer whose inputs have not changed since the last build. This is what makes container builds reproducible across machines and dramatically faster on repeat runs.

Writing Dockerfiles by hand is the foundational skill that everything else in the container ecosystem (compose stacks, Kubernetes manifests, CI/CD pipelines, registry workflows) sits on top of. Sloppy ordering produces 800 MB images that take three minutes to push; careful ordering produces 25 MB images that rebuild in seconds. This lab uses a small static website as the canvas to give you a working mental model for how BuildKit assembles, caches, and invalidates layers - so that the Dockerfiles you write next, for your own applications, are fast, small, and predictable from the start.

Objectives

Upon completion of this beginner level lab, you will be able to:

  • Author a Dockerfile and build a tagged custom image using FROM, WORKDIR, COPY, EXPOSE, and CMD.
  • Run the built image as a container and verify it serves the expected content over HTTP.
  • Inspect image layers with docker image history and observe how edits invalidate the BuildKit cache.
  • Use a .dockerignore file to control what enters the build context.

Who is this lab for?

This lab is designed for:

  • Engineers and students taking their first hands-on steps with Docker
  • DevOps practitioners who want to write smaller, faster, more cache-friendly images for their CI/CD pipelines

Verified against your live environment

An automated validation engine inspects your actual resources and configurations as you work. Completion means the task was performed — not multiple choice, real-world proficiency.

[CHECK] validation_activelive
Inspecting deployed resources...
Verifying configuration state...
✓ Step requirements satisfied

More labs like this

PremiumIncluded in Premium
Duration
60 min
Steps
4

Environment

Dedicated VM IDE

Every lab includes

  • Real environment, pre-credentialed
  • Automated checks on every step
  • Isolated sandbox, auto cleanup
  • AI-recommended next steps

Lab curriculum

  1. 01

    Getting Started with Docker IDE

  2. 02

    Author Your First Dockerfile for a Static Site

    1 automated check

  3. 03

    Observe Layer Caching and Add a Dockerignore File

    1 automated check

  4. 04

    Run and Verify the Custom Image Serves Content

    1 automated check

Skills validated

DockerDockerfile

Not the lab you were looking for?

Browse 150+ hands-on labs across AWS, Azure, Kubernetes, Docker, and cloud security.

Explore the catalog