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

Transcript

Is your container a gigabyte, for a hundred-line service? Many container images start from a full operating system. They carry compilers, shells and download caches into production. Your service needs none of that to run. Every deploy stores it, pulls it and starts it, on every machine. That is storage, network traffic and start-up work, again and again. Here is the fix you can use today. Start from a slim base image, like alpine or distroless. GreenCode researchers found that big container images waste energy. The GreenCode Constitution notes these can be ten to a hundred times smaller. Build in stages, and copy only what the service needs to run. Leave test tools and build tools out of the final image. Get this right using GreenCode's Constitution skill for AI agents, and Docker's build guide. A smaller image means less to store, send and start. GreenCode helps tackle this by mapping your running services and the energy each one uses. It shows which services cause the energy use, and which barely run. That was GreenCode Tech Tip number eight. Follow for the next tip, and find more on greencode.ai/tech-tips.

All GreenCode Tech Tips · All GreenCode videos

  • Tip #8
  • For Ops and infrastructure
  • Length 1:13
  • Category Containers, Kubernetes and serverless
GreenCode

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

Get in touch