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

0
19
Asked By CuriousCoder42 On

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!

4 Answers

Answered By GlobbingGuru On

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.

CuriousCoder42 -

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

Answered By ProfilePro On

One alternative is to add different profiles for your services and organize them that way. It helps in managing what gets started without confusion.

CuriousCoder42 -

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.

Answered By BinaryNinja On

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.

Answered By ShellSavant On

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!

TechWhiz92 -

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

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.