DevOps with Docker and Kubernetes
LESSON 1.2

Layers, caching, and multi-stage builds

Learn key techniques and workflows in DevOps with Docker and Kubernetes.

6m
advanced
8,194 students

Overview

Instruction order decides your build time. Copy dependency manifests before source, and use a multi-stage build to leave the toolchain behind.

In this lesson you will:

  • Order instructions so the cache survives code changes
  • Separate build and runtime with multi-stage builds
  • Cut image size and shrink the attack surface

Pro Tip

Copy your lockfile and install dependencies before copying source. Otherwise every edit invalidates the install layer.

Resources