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.
Below we step through each issue in detail with examples and practical notes.
- Packages re-download on every build
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):
- 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.
- Secrets leak into image metadata or layers
API_KEY can show up in image history. For example:
ENV API_KEY=mysecretkeybakes 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.
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.
- Use BuildKit’s
--secretflag 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.
- Architecture lock-in
- Use
docker buildxto 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.
- Buildx / BuildKit docs
- QEMU cross-architecture emulator: https://www.qemu.org
- Independent stages run sequentially
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:
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.

- Docker Documentation: https://docs.docker.com/
- BuildKit/docs and buildx: https://docs.docker.com/build/buildx/
- QEMU: https://www.qemu.org/