How can I start services with names that match a pattern in Docker Compose?

January 21, 2026 4 answers
Asked by !weigh the flour
Hey everyone! I have a few services set up: `foobar`, `foobaz`, `barfum`, and `barqux`. I'm trying to start only the ones that start with `foo`. I've attempted using `docker compose up foo*` as well as variations like `'foo*'`, `"foo*"`, and others, but nothing seems to work. Is there a way to do this with Docker Compose? I feel like I'm not the first one with this issue. Thanks for your help!

Answers

hatchback.mileage
You can use this command: `docker compose up $(docker compose config --services | grep '^foo')`. It filters the services based on your pattern and starts them properly!

403 missing page: Exactly! Just remember that this approach uses shell features, so make sure you're comfortable with them.

Reply to this answer
BASALT
For globs to work in this context, Docker must accept multiple arguments. Unfortunately, passing `foo*` as an argument seems not to be supported. You could look into using `find` and `xargs` for starting them in sequence.
Reply to this answer
climbing_rope_check
One alternative is to add different profiles for your services and organize them that way. It helps in managing what gets started without confusion.

!weigh the flour: Yeah, I'm using profiles for now, but it complicates my commands since I always have to specify `--profile`. It would be much easier if it only triggered specific services.

Reply to this answer
_206 bones to learn
Just a heads up, the globbing happens at the shell level and not within Docker. This means that patterns like `foo*` wonโ€™t match services unless they're explicitly defined. That's why your command didn't work as expected.

!weigh the flour: I thought that might be the case since I got an error saying 'no such service: foo*'. Thanks for clarifying!

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions