Skip to main content
Earlier we built and pushed a Docker image to Docker Hub. The basic flow is straightforward: author a Dockerfile, run docker build, push the image to a registry, and you’re done. That workflow is sufficient for small experiments. However, in real projects several friction points emerge. This lesson walks through four concrete problems with the traditional Docker build engine and shows why they matter in CI/CD and production workflows. Later lessons will cover how modern build systems (BuildKit, buildx, remote builders) address these issues. The four problems are:
  • Packages are re-downloaded on every build.
  • Secrets leak into image metadata or layers.
  • The build is locked to the machine’s CPU architecture.
  • Independent stages run sequentially instead of in parallel.
Summary table Below we step through each issue in detail with examples and practical notes.
  1. Packages re-download on every build
When a Dockerfile runs package managers (e.g., apt-get, pip, npm) in a RUN step, the package manager downloads artifacts and may cache them temporarily inside the container layer. But most package manager caches are discarded when the layer completes. When a later layer changes (for example, a minor source code edit), the cache for the earlier layer may be invalidated and the package install step re-runs — re-downloading the exact same packages. Example console output (first build then a rebuild that re-downloads the same packages):
Why this matters: on slow connections or in CI, re-downloading dependencies can add many minutes to each build. To avoid repeated downloads, prefer:
  • Proper layer ordering: install dependencies before copying frequently-changing source files.
  • Use package-manager caches exposed to the build cache (or mount caches during build).
  • Use a modern build backend (BuildKit/buildx) with remote caching or exportable build caches to speed subsequent builds and CI jobs.
  1. Secrets leak into image metadata or layers
Many builds require credentials: API keys for private artifact registries or SSH/Git credentials to fetch private repositories. Passing secrets as build arguments or baking them into environment variables is risky. Unsafe example (Dockerfile snippet):
And the build command:
That API_KEY can show up in image history. For example:
Other pitfalls:
  • ENV API_KEY=mysecretkey bakes the secret into a layer and makes it visible at runtime.
  • Copying a secret file into the image and deleting it in a later layer does not remove the secret from earlier layers (layers are additive).
  • Pushing intermediate images (for remote cache) can accidentally publish secrets.
Multi-stage builds can reduce risk by keeping secrets in an intermediate stage and only copying final artifacts into the runtime stage. But this is fragile if intermediate stages are pushed to registries or left in the local daemon. Example patterns that people try (and why they fail or remain fragile):
Build command:
Never pass production secrets directly as build arguments or bake them into image layers. Build-time secrets require a build system that provides ephemeral secrets to the build without embedding them into final artifacts.
Better approaches:
  • Use BuildKit’s --secret flag or other ephemeral secret forwarding mechanisms so secrets are available during a RUN step but never written into layers.
  • Use mounted sockets or external secret providers during builds that do not persist secret material inside image layers.
  1. Architecture lock-in
A Docker image is typically built for the CPU architecture of the machine performing the build. Builds on x86_64 (amd64) produce amd64 images; builds on Apple Silicon create arm64 images. An image built for the wrong architecture fails at runtime or is incompatible with registries that host multi-arch manifests. Examples: Build on amd64 and try to run on ARM server:
Build on arm64 and try to pull on amd64 production:
Mitigations:
  • Use docker buildx to build multi-architecture images and push a manifest list containing multiple platform images.
  • Configure CI to run builds on each target architecture or use QEMU emulation for cross-building (see QEMU).
  • Use a remote builder service that produces multi-arch artifacts.
Relevant links:
  1. Independent stages run sequentially
A Dockerfile with multiple FROM stages often contains unrelated work: building a frontend artifact and compiling a backend binary, for example. The legacy builder runs stages one after another even if they are independent, which increases wall-clock build time. Example Dockerfile:
Because the traditional builder executes stage A fully before starting stage B, builds take longer than necessary. Modern build engines can execute independent stages in parallel and share caches more effectively. Root cause and wrap-up All four problems stem from the same root cause: the legacy build engine was designed for a simpler era and lacks features modern teams expect — robust caching, ephemeral build-time secrets, cross-platform image creation, and parallelized stage execution. Newer build engines and tools (BuildKit, buildx, remote caching) address these specific shortcomings.
Modern build systems provide features like build-time secret forwarding (without baking into layers), per-stage parallelism, and cross-platform image building to solve the problems described above.
A slide titled "Four problems" lists four issues: "Packages re-download," "Secrets leak," "Architecture lock-in," and "Sequential stages." An arrow points from these boxes to a large square with a question mark labeled "legacy builder — too old."
Links and references

Watch Video