Patch container base images on a fixed schedule by rebuilding each image from the latest patched upstream tag, running automated tests, and redeploying through the same pipeline you use for application code. A weekly or fortnightly cadence, plus an emergency path for critical vulnerabilities, covers the common case.
Key takeaways
- A container image is a build artefact, so the durable fix for an outdated base image is a new image rather than a patched running container.
- Choose a rebuild cadence your team can test and deploy within, and add an out-of-band rebuild for critical advisories.
- Pin base images to a version or digest so that each rebuild changes only what you deliberately update.
- Gate every scheduled rebuild with tests and a vulnerability scan before anything reaches production.
Why rebuild instead of patching in place?
Rebuilding is the reliable option because a container image is immutable once built. Patching packages inside a running container leaves no trace in the image you deploy, so the next replacement quietly brings back the old version.
A Dockerfile begins with a base image, and each instruction adds a layer on top of it. The operating system packages come from that base, so updating them means pulling a newer base and building again. The Docker documentation describes this layered build model, which is why the rebuild, not the running container, is the unit you should manage.
Patching in place still has a place as a short emergency measure while a rebuild is prepared. It should never be the end state, because it creates drift between what is running and what is recorded in source control.
How often should you rebuild?
Rebuild on a fixed cadence that matches how quickly your team can test and deploy, and add an unscheduled rebuild whenever a critical advisory affects a package in your image. Weekly or fortnightly works for many teams, but the right interval depends on your release process rather than on a universal rule.
A short cadence reduces the time an image stays vulnerable, but it increases the number of rebuilds you must review. If every rebuild produces a failed test run that nobody investigates, the schedule adds noise instead of safety. A longer cadence means fewer reviews, but each review contains more changes, which makes failures harder to trace.
Scheduled rebuilds versus emergency rebuilds
The scheduled rebuild handles routine drift. The emergency rebuild handles a specific advisory for a package you ship. Keep both on the same pipeline so that the emergency path does not bypass tests entirely; it should only shorten the review window.
What should the rebuild pipeline check?
The pipeline should build the image, run the test suite, scan the result for known vulnerabilities, and publish the image only if every gate passes. Each check answers a different question, so none of them replaces the others.
- Build from a pinned base image reference, so that the output is reproducible.
- Run unit, integration and smoke tests against the new image, not against a developer machine.
- Scan the image and compare findings with the threshold your team has agreed.
- Record the base digest, image digest and build time so that every deployed image can be traced.
- Deploy to a staging environment first, then promote the same image to production.
Promoting the identical image, rather than rebuilding for each environment, is what makes the test results meaningful. If production receives a different artefact from the one that was tested, the schedule no longer provides the assurance it appears to give. Teams that manage several services often find this easier to organise with a shared pipeline template, which is a common part of cloud and DevOps engineering work.
When does a scheduled rebuild fail, and what then?
A scheduled rebuild fails when the new base image changes something your application depends on, when a test is flaky, or when the upstream tag is withdrawn or moved. The response should be a documented rollback to the last known good image, followed by a fix to the cause.
Floating tags such as latest cause the most confusing failures, because the image changes without any change in your repository. A pinned version makes a failure traceable to one deliberate update. Scheduled rebuilds also fail quietly when the pipeline itself breaks, for example when a registry credential expires, so monitor for missing builds, not only failed ones.
Hypothetical examples of a rebuild schedule
Here are two hypothetical scenarios:
Scenario one. A team runs a fortnightly rebuild with pinned tags. The scheduled build changes one operating system package, the smoke tests fail on a date-formatting function, and the team pins the previous image while they fix the function and release again.
Scenario two. A team uses a floating tag. A production container restarts after a node failure and behaves differently, and nobody can identify which base image it used. The fix is to pin the tag and record digests in every build.
Both scenarios are illustrative only. They show where the pipeline should catch a problem, not what any particular team experienced.
Who owns the schedule?
One named engineer or team should own the schedule, the pipeline and the review of failures. Without a clear owner, the rebuild runs but nobody acts on its output, which leaves the images as outdated as before.
Ownership includes deciding the threshold for blocking a release, approving base image upgrades that change major versions, and retiring images that are no longer used. A short written runbook describing these decisions is more useful than a long policy document that nobody reads during an incident.
For teams that want to connect container builds with systems such as an ERP or an e-commerce platform, the same discipline applies to the integration layer. Our cloud architecture and DevOps guides cover related practice in more depth, and the baseline for securing cloud infrastructure explains the surrounding controls.
Frequently Asked Questions
How often should I rebuild base images?
The cadence should match how quickly your team can test and deploy a new image, which for many teams means weekly or fortnightly. Add an out-of-band rebuild when a critical vulnerability is announced for a package in your image. Fix the schedule to a recurring day so that failures are reviewed in a predictable slot.
Should I pin base image tags or follow a floating tag?
Pin to a specific version or digest so that each build is reproducible, and update the pin deliberately. A floating tag such as latest can change without warning, which makes failures hard to trace. Use the scheduled rebuild to move the pin forward once the tests pass.
Does a scheduled rebuild replace vulnerability scanning?
No, a scheduled rebuild refreshes packages, while scanning shows what remains vulnerable in the result. Run a scanner against each new image and fail the pipeline on findings above your agreed threshold. The two practices work together, and neither covers flaws in application code on its own.
Can Rui Codex set up this pipeline for my team?
Rui Codex offers cloud and DevOps engineering, and the scope of any container pipeline work depends on your current environment. A consultation is the usual starting point, where your images, registry and deployment process are reviewed. You can request one through the contact page or by email.
Sources
- Docker Documentation - Docker, Inc.