Tech Tip #8: Slim your container images

Is your container a gigabyte, for a hundred-line service?

Video created by explainapaper.com

The problem

Images built on full operating-system bases carry compilers, shells and package caches into production. Every deploy stores, pulls and starts all of it, on every node.

The fix you can use today

  • Use slim, alpine or distroless base images.
  • Build with multi-stage Dockerfiles and copy only the runtime artefacts.
  • Leave dev dependencies and build tools out of the final image.

GreenCode researchers found that big container images waste energy.

Tools that help

  • GreenCode Constitution skill (GreenCode researchers): open-source energy principles and a catalogue of 37 energy anti-patterns that an AI coding agent can follow to find and fix waste like this
  • Docker build best practices (Docker): multi-stage builds, small base images and leaving build tools out of the final image

How GreenCode helps

GreenCode helps tackle this by mapping your running services and tracing energy and CO2e to the services that cause it. It shows which services run hot and which barely run at all. More on this.

Tags

#docker#ci-cd#cloud

Sources

All GreenCode Tech Tips

  • Tip #8
  • For Ops and infrastructure
  • Category Containers, Kubernetes and serverless
  • Format short video
GreenCode

Want this checked on your own system? Talk to the GreenCode team.

Get in touch