How to upgrade docker container after its image changed
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
A running Docker container does not auto-refresh when its image is updated. To apply a new image, you replace the container while preserving required runtime settings and persistent data. A good upgrade runbook includes pull, replace, health verification, and rollback.
Core Sections
1. Treat upgrades as container replacement
Containers are immutable runtime instances created from images. Once started, they keep using the original image layers even if a newer tag exists remotely. That means an upgrade is a recreate operation, not an in-place mutation.
Typical upgrade sequence:
- Pull target image tag.
- Stop and remove old container.
- Start new container with equivalent options.
- Validate service health.
2. Pull exact image version
Use explicit version tags, not mutable tags, for predictable rollouts.
If your team supports digest pinning, store and deploy by digest to guarantee byte-identical rollouts across environments.
3. Preserve runtime configuration before replacement
Most failures come from forgetting flags used by the old container. Capture current settings before removing it.
Important settings to preserve:
- published ports
- environment variables
- mounted volumes
- network aliases
- restart policy
If configuration is already defined in Compose or orchestration manifests, prefer those sources over manual reconstruction.
4. Recreate the container with the new image
Volume-backed data remains available after container replacement, which is why volume mapping must be preserved exactly.
5. Use Docker Compose for repeatable upgrades
Compose reduces manual flag drift and is usually safer than direct docker run for services with several settings.
--no-deps upgrades one service without restarting unrelated dependencies. Use full stack restart only when dependency contracts changed.
6. Validate health before traffic cutover
A container in running state is not proof of application readiness. Validate endpoints and logs:
If app initialization takes time, use health checks and wait conditions in deployment workflow before switching traffic.
7. Prepare and test rollback path
Keep previous stable image tag available until the new version proves stable. Rollback should be a documented command set, not an improvised response.
For zero-downtime services, use blue-green style rollout and switch load balancer targets only after new container passes checks.
8. Clean up safely after stabilization window
After observing stable behavior for a defined window, remove unused artifacts:
Do cleanup after rollback window, not immediately after deployment.
Common Pitfalls
- Pulling a new image but forgetting to recreate the running container.
- Recreating container without original env vars, ports, or volumes.
- Deploying mutable tags such as
latestin production environments. - Declaring rollout complete before health and log checks pass.
- Deleting old images too early and slowing incident rollback.
Summary
- Docker upgrades after image changes are replacement workflows.
- Use explicit version tags and preserve runtime configuration.
- Prefer Compose or declarative manifests for repeatability.
- Validate readiness before routing real traffic.
- Keep rollback commands and previous stable images ready.
Related reading
- How to use --volume option with Docker Toolbox on Windows?
- How to use an init container to check if MySQL is ready for connections?
- How to use bash with an Alpine based docker image?
- How to use Docker Image in ECR with AWS EKS
- How to upload and deploy zip file to AWS elastic beanstalk via CLI?
- How to upsize volume of Terraformed EKS node
- How to use docker in distributed systems
- How to use host network for docker compose?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.