Docker-compose --force-recreate specific service
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
If you want to recreate only one service in a Compose project, the usual command is to target that service explicitly with up --force-recreate. In modern Docker installations, the command is usually docker compose, while older setups used docker-compose. The core behavior is the same: Compose stops and replaces the container for the named service even if its configuration has not changed.
Recreate a Specific Service
For a single service called web, use:
On older installations:
This tells Compose to recreate the web service container instead of deciding that the existing container is already good enough.
What --force-recreate Actually Does
The flag tells Compose to recreate containers even if it thinks nothing changed in the service definition or image configuration.
That usually means:
- stop the existing container for that service
- remove it
- create a new container from the service definition
- start the new container
It does not automatically delete named volumes. That is an important detail people often get wrong.
Use --no-deps When You Really Mean Only That Service
If the service has dependencies and you do not want Compose to touch them, add --no-deps.
This is often the real answer when someone says “recreate just this one service.” Otherwise Compose may still consider dependency relationships during startup.
Difference Between Recreate and Rebuild
--force-recreate is not the same as rebuilding the image.
If the image needs rebuilding from the Dockerfile, use:
If the image is already correct and you only need a fresh container instance, --force-recreate alone is enough.
This distinction matters because many people use recreate to solve what is actually a stale-image problem.
Difference Between restart and up --force-recreate
Restarting:
only stops and starts the existing container. It does not replace it.
Recreating:
creates a new container instance. That matters when:
- environment values changed
- entrypoint behavior must rerun from a fresh container
- anonymous container state must be discarded
- labels or service definitions changed
If you need a truly fresh container, restart is not enough.
Check the Result
After recreating the service, inspect its status:
And if needed:
This confirms the service actually came back healthy instead of just being replaced with a failing container.
When to Use rm First
Sometimes you will also see workflows like:
This is valid, but up --force-recreate web is usually simpler and expresses the intent more clearly. Reach for manual rm only when you have a specific reason to separate removal from recreation.
Volume and State Considerations
Recreating a container is not the same as deleting its persistent data. If your service uses named volumes, those volumes remain unless you explicitly remove them.
That is usually what you want. It means you can recreate the application container without losing durable service data. But if you expected a total reset, container recreation alone will not deliver that.
Compose V1 Versus V2 Syntax
Modern Docker uses the plugin form:
Older environments used:
If you are writing documentation or internal runbooks today, prefer docker compose unless your environment is explicitly pinned to the standalone legacy binary.
Common Pitfalls
The biggest mistake is assuming --force-recreate rebuilds the image. It does not. Another is forgetting --no-deps when you truly only want one service touched. Developers also often think recreation deletes volumes, which is incorrect for named volumes. Finally, using restart instead of recreation can leave you with the same stale container instance when you actually needed a fresh one.
Summary
- To recreate one service, use
docker compose up -d --force-recreate service_name. - Add
--no-depsif you do not want dependency services affected. - Add
--buildif the image also needs rebuilding. - Recreate replaces the container; restart only stops and starts the same one.
- Recreating a container does not automatically remove named volumes.

