When I change one line for one service in a Compose file, I want exactly that service to restart. Plain docker compose up -d web doesn’t quite promise that. The docs say up also starts any linked services unless they’re already running, so the services web depends on come along for the ride. For a stack with a database underneath, I’d rather say exactly what I want.
Add --no-deps and Compose only deals with the services you name. The docs describe it as “Don’t start linked services”:
docker compose up -d --no-deps web
Say you bumped the image tag of the web service and want only that container replaced. With --no-deps, Compose works on web alone and leaves the database out of it. It pairs nicely with a pull of just that service:
docker compose pull web
docker compose up -d --no-deps web
Compose still decides on its own whether web needs recreating, based on its config and image. If nothing changed it just leaves it running. Add --force-recreate when you want a fresh container anyway.
The caveat is in the name. Compose won’t start anything the service depends on, so if the database is stopped, web comes up without it and will probably crash or keep retrying. The depends_on conditions such as service_healthy are skipped too. I’d only reach for --no-deps when the rest of the stack is already up and healthy, and use plain docker compose up -d when you’re starting from scratch.
Further reading: docker compose up reference