Home Explore Blog CI



docker

1st chunk of `content/manuals/build/cache/_index.md`
31e53f3b3d157db86394633729f632cded75cb698f44328a000000010000044b
---
title: Docker build cache
linkTitle: Cache
weight: 60
description: Improve your build speed with effective use of the build cache
keywords: build, buildx, buildkit, dockerfile, image layers, build instructions, build context
aliases:
  - /build/building/cache/
  - /build/guide/layers/
---

When you build the same Docker image multiple times, knowing how to optimize
the build cache is a great tool for making sure the builds run fast.

## How the build cache works

Understanding Docker's build cache helps you write better Dockerfiles that
result in faster builds.

The following example shows a small Dockerfile for a program written in C.

```dockerfile
# syntax=docker/dockerfile:1
FROM ubuntu:latest

RUN apt-get update && apt-get install -y build-essentials
COPY main.c Makefile /src/
WORKDIR /src/
RUN make build
```

Each instruction in this Dockerfile translates to a layer in your final image.
You can think of image layers as a stack, with each layer adding more content
on top of the layers that came before it:


Title: Understanding Docker Build Cache
Summary
This section explains how the Docker build cache works and how to optimize Dockerfiles for faster builds. Each instruction in a Dockerfile translates to a layer in the final image, creating a stack of layers.