Skip to Content
Zurück zu: GitOps with ArgoCD: Managing Kubernetes Infrastructure Declaratively
DevOps & CI/CD 6 min. read

Optimizing Container Images: From 1.2 GB to 45 MB

Large Docker images slow down CI/CD pipelines and deployments. With multi-stage builds and best practices, you can drastically reduce image size.

devRocks Engineering · 08. February 2026 · Aktualisiert: 31. March 2026
Docker CI/CD Container Performance
Optimizing Container Images: From 1.2 GB to 45 MB

Why Image Size Matters

A 1.2 GB Docker image means: slower builds, slower pushes to the registry, slower pulls on the nodes, and a larger attack surface. Smaller images are faster and more secure.

Multi-Stage Builds

The most important lever: separate build dependencies from runtime dependencies. In the build stage, install compilers, build tools, and dev dependencies. Into the final stage, copy only the compiled artifacts.

Base Image Selection

  • Alpine: ~5 MB base image, ideal for Go and Rust applications. Caution with PHP and Python — musl vs. glibc can cause compatibility issues.
  • Distroless: Google's Distroless images contain only the runtime — no shell, no package managers. Maximum security.
  • Debian Slim: A good compromise between compatibility and size for PHP and Node.js applications.

Layer Optimization

  • Order: Rarely changing layers (OS, dependencies) before frequently changing layers (app code) — maximum cache utilization.
  • .dockerignore: Exclude node_modules, .git, tests, and documentation from the build context.
  • Combine: Consolidate multiple RUN commands into a single layer to avoid intermediate layers.

Results

Using these techniques, we reduced the image size from 1.2 GB to 45 MB in a client project. Build time dropped from 8 to 2 minutes, and deployments are three times faster.

Questions About This Topic?

We are happy to advise you on the technologies and solutions described in this article.

Get in Touch

Seit über 25 Jahren realisieren wir Engineering-Projekte für Mittelstand und Enterprise.

Weitere Artikel aus „DevOps & CI/CD“

Frequently Asked Questions

The size of container images significantly impacts the speed of builds, pushes, and pulls. Smaller images lead to faster processes in the CI/CD pipeline and also reduce the attack surface, enhancing security.
Multi-stage builds allow for the separation of build dependencies from runtime dependencies. This ensures that only the necessary, already compiled artifacts are included in the final image, which reduces the overall size.
The Alpine image is recommended for Go applications as it is only about 5 MB in size. It provides a lightweight and efficient foundation, but compatibility should be considered since it may cause issues with certain applications like PHP or Python.
Layer optimization is achieved by placing rarely changing layers, such as the operating system or dependencies, at the top and more frequently changing layers, like application code, further down. Additionally, .dockerignore files should be used to exclude unnecessary files from the build.
By reducing the size of container images, you benefit from faster build and deployment times as well as more efficient use of your infrastructure. In one example project, we managed to reduce the build time from 8 minutes to 2 minutes and perform deployments three times faster.

Didn't find an answer?

Get in touch