✦ For everyone, free.

Practical knowledge for real and everyday life

Home

1.1.2.3 Drift Reduction

A focused guide to Drift Reduction, connecting core concepts with practical Docker and container operations.

Drift reduction refers to the way Docker limits configuration drift — the gradual, unintended divergence between environments that are supposed to be identical (such as staging and production, or one developer's machine and another's) — by replacing manually maintained environments with environments instantiated from a single shared image.

What Configuration Drift Looks Like Without Containers

In traditional deployments, each environment is configured independently: packages are installed over time, patched at different schedules, and occasionally modified directly by an engineer fixing an urgent issue. Over months, environments that started identical accumulate small differences — a missing patch, an extra package, a configuration file edited by hand and never recorded — until a deployment that works in one environment fails in another for reasons that are hard to trace.

How Images Eliminate the Source of Drift

A Docker image is built once from a Dockerfile and then reused unchanged across every environment it is deployed to. There is no per-environment manual installation step where drift could be introduced, because the environment's content is the image itself.

docker build -t myapp:1.0 .
docker tag myapp:1.0 registry.example.com/myapp:1.0
docker push registry.example.com/myapp:1.0

Staging and production both run:

docker pull registry.example.com/myapp:1.0
docker run -d --name myapp registry.example.com/myapp:1.0

Since both pulls retrieve the exact same image digest, there is no opportunity for the two environments' application layers to differ.

Drift Reduction Through Immutability

Containers are typically treated as disposable: instead of patching a running container in place, the image is rebuilt and the container is replaced. This habit, encouraged by how Docker is normally used, prevents the kind of incremental hand-editing that causes drift in long-lived servers.

docker stop myapp && docker rm myapp
docker run -d --name myapp registry.example.com/myapp:1.1
Detecting Drift That Still Occurs

Drift can still creep in through external state — mounted volumes, host-level configuration, or environment variables injected outside the image. Comparing the running container's actual configuration against the image's declared defaults helps catch this category of drift.

docker inspect myapp --format '{{json .Config.Env}}'
docker diff myapp

docker diff reports any filesystem changes made inside a running container relative to its image, which is a direct way to detect drift that has occurred since the container started.

Drift Reduction Across a Fleet

When many hosts run containers from the same registry-hosted image, an orchestrator can verify and enforce that every replica is running the intended tag, correcting any host that has fallen out of sync.

docker service update --image registry.example.com/myapp:1.1 myapp

This makes drift reduction an ongoing, enforced property of the deployment rather than a one-time guarantee at release time.