JJJJJJ
JJJJJJ

Reputation: 63

how to run multiple docker-compose at once

I have 4 folders inside a directory. each folder represents a container on its own. each container has its own docker-compose.yaml file. Currently, when I want to run them I have to open up a command prompt and docker-compose up for each of them. Is there a way to run them all at once with a script or something?

Project
|-dir1
|  |--docker-compose.yaml
|-dir2
|  |--docker-compose.yaml
|-dir3
|  |--docker-compose.yaml
|-dir4
|  |--docker-compose.yaml

Upvotes: 0

Views: 953

Answers (1)

David T.
David T.

Reputation: 1065

There are two ways to go about it:

  1. Specify the -f flag multiple times, once for each file (e.g. docker compose -f ./dir1/docker-compose.yaml -f ./dir2/docker-compose.yaml up). This will merge the configs and run all services in the same network.
  2. Use the -p, --project flag to change the default project when running each (e.g. docker compose -f ./dir1/docker-compose.yaml -p dir1 up). This will make it so each will be run in a different network and the runs won't collide with each other.

https://docs.docker.com/compose/reference/#use--p-to-specify-a-project-name

Upvotes: 1

Related Questions