Skip to main content
Cloud / DevOpsContainers & OrchestrationDiagramBeginner

Docker Layer

KO: 도커 레이어·EN: Docker Layer·JA: Dockerレイヤー

Read-only filesystem layers produced by each Dockerfile instruction and stacked via OverlayFS, enabling layer caching and disk sharing across containers

Table of Contents

Structure Diagram

Docker Image Layer Stack (Immutable RO Layers + Writable Layer)
TIMELINE5 steps
STEP 1Base OS(RO · Shared)
Quick Answer

What is Docker Layer?

Read-only filesystem layers produced by each Dockerfile instruction and stacked via OverlayFS, enabling layer caching and disk sharing across containers. It is a core concept in Containers & Orchestration within Cloud / DevOps.

Core Principles

A Docker Layer represents the filesystem diff created by a single Dockerfile instruction (FROM, RUN, COPY), stored as an immutable, content-addressable read-only layer. At runtime, OverlayFS merges these layers into a unified view and mounts a thin writable container layer on top using Copy-on-Write (CoW).

Because unchanged lower layers are cached and shared across images and running containers, builds, pushes, and node pulls only transfer the deltas that actually changed.

Practical Takeaways

  • Order instructions from least to most frequently changed: Copy dependency manifests (package-lock.json, go.mod) and install packages before running COPY . . so everyday source edits never invalidate the dependency layer cache.
  • Clean up temporary files in the same RUN layer: Deleting a file in a subsequent RUN instruction only writes a whiteout marker and does not shrink the image; chain download, install, and rm -rf in one command.
  • Maintain a strict .dockerignore: Exclude .git, node_modules, and local build artifacts so they never bloat layers or bust caches.

Notable Examples

  • Production Web App Dockerfiles: Separating lockfile installation from app source copy cuts CI image rebuilds from minutes to seconds.
  • Kubernetes / containerd Node Caching: Shared base OS layers are pulled once per node and reused by dozens of pods.
  • dive CLI: Inspects layer-by-layer size and wasted bytes during container image optimization.