Redeploy spring-boot application in docker container?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Redeploying a Spring Boot application in Docker usually means rebuilding the application image and replacing the running container with one based on the new image. The exact commands depend on whether you are using plain Docker, Docker Compose, or an orchestrator, but the principle is the same: a container is treated as disposable, while the image is the versioned artifact you replace.
The Basic Redeploy Flow
A straightforward redeploy has these steps:
- build the new Spring Boot jar
- build a new Docker image
- stop and remove the old container
- start a new container from the new image
That is the common local and small-server workflow.
Build the Spring Boot Application First
For Maven:
For Gradle:
That produces the updated application artifact, usually under target/ or build/libs/.
Example Dockerfile
A simple Spring Boot Dockerfile looks like this:
After rebuilding the jar, rebuild the image:
That image now contains the new application version.
Replace the Running Container
If you are using raw Docker commands:
This is the standard replace-the-container workflow. You do not "update the container" in place. You replace it with a new one built from the new image.
Docker Compose Redeploy
If the app is managed by Compose, the usual redeploy command is even simpler:
This rebuilds the image if needed and recreates the service container.
A minimal Compose example:
Compose is often the easiest option when the app also depends on services such as Postgres, Redis, or another internal API.
Keep Configuration Outside the Image
A redeploy becomes much cleaner when configuration is externalized through environment variables, bind mounts, or secrets rather than baked into the image.
Example:
That way, rebuilding the app image does not require rewriting environment-specific configuration inside the container filesystem.
What About Zero-Downtime Deployment
The stop-remove-run sequence causes a brief interruption. For development or internal tools, that is often acceptable. For production traffic, you usually want a safer rollout pattern such as:
- blue-green deployment
- rolling replacement behind a load balancer
- orchestrated updates in Kubernetes or another platform
The key point is that Docker alone gives you container replacement, but higher-level deployment guarantees usually come from surrounding infrastructure.
Verify the New Deployment
After redeploying, check both container state and application health.
This helps distinguish:
- image built successfully
- container started successfully
- Spring Boot application actually became healthy
Those are not the same thing.
Common Pitfalls
- Rebuilding the jar but forgetting to rebuild the Docker image.
- Restarting the old container and expecting new code to appear magically.
- Baking environment-specific settings into the image instead of externalizing them.
- Treating redeploy as an in-place container mutation instead of an image replacement.
- Skipping post-deploy health checks and assuming a running container means a healthy app.
Summary
- Redeploying a Spring Boot app in Docker means building a new image and replacing the running container.
- With plain Docker, the common flow is build, stop, remove, and run.
- With Docker Compose,
docker compose up -d --buildis the usual shortcut. - Keep configuration outside the image so redeploys stay clean and repeatable.
- Always verify both container status and application health after the replacement.
Related reading
- Redirecting command output in docker
- Reloading code in a dockerized node.js app with docker-compose
- Remove Docker images from Nexus Repository Manager OSS 3.0.1-01
- Remove Kubernetes Readiness Probe
- redesign a shared memory distributed system with message passinig
- Redis how to update master from slave?
- Reduce RabbitMQ memory usage
- Reference Microsoft.SqlServer.Smo.dll

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.