Restart one Docker Compose service
Restart selected service containers without applying new configuration, or recreate them deliberately when the image or settings change.
Use a Compose service name to target the service you intend to restart. Add --no-deps when you want to suppress dependent-service restart propagation:
docker compose restart --no-deps web
This stops and starts the existing service containers. It does not adopt changed environment settings from the Compose file or replace them with newly built images. If web has several replicas, the command targets the service's containers, not a single chosen replica.
Restart versus recreate
# Apply changed web configuration without starting its dependencies.
docker compose up -d --no-deps web
# Build image-baked code and apply the resulting image to web.
docker compose up -d --build --no-deps web
| Operation | New container configuration | New image |
|---|---|---|
restart |
Retains existing settings | Retains existing image |
up -d |
Applies detected changes | Uses the selected available/pulled image according to policy |
up -d --build |
Applies detected changes | Builds first, with normal cache behavior |
A plain up does not guarantee that source changes have been built into the image. Bind-mounted code is different: the changed files may already be visible, and an application reload or restart may be enough.
--no-deps has operation-specific meaning. With up, it avoids starting linked/dependent services for the target; with restart, it prevents restarting dependent services. Dependencies configured with restart propagation are a reason not to promise that bare restart web can never affect another service.
Prefer a supported reload when appropriate
For an Nginx service whose configuration is already available inside the container:
docker compose exec web nginx -t
docker compose exec web nginx -s reload
Reload only after validation succeeds. A reload uses the application's own behavior; it does not change the image or container environment.
Then check status, logs, and the request that originally failed:
docker compose ps web
docker compose logs --tail 100 web
For services already sending logs to Guance, compare errors around the restart while retaining service and container identifiers in the collection configuration. A healthy container state alone does not establish that a business request works.
FAQ
Why did my configuration change not appear? Restart keeps the existing container settings. Apply configuration with up; rebuild first when the changed file belongs inside the image.
Will the database restart too? Do not rely on a blanket rule. Examine dependencies and their restart settings; use the appropriate --no-deps flag when isolating the operation, and ensure the selected service can tolerate the current dependency state.
Can I restart exactly one replica? Use docker compose ps to identify it, then docker restart its container name or ID. Plan for reduced capacity. Ordinary single-host Compose restart does not provide a Kubernetes-style rolling-update guarantee; --scale alone does not make the operation zero-downtime.
See Compose restart reference, Compose up reference, Compose service configuration.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan