Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I have multiple docker compose yaml files in same directory?

Can I keep multiple docker-compose.yml files in same directory? e.g.

i want docker-compose-1.yml with some services and docker-compose-2.yml with some other services. Is there any requirement to have specific file names and what is the command used to start it ?

docker-compose up --build -f docker-compose-1.yml ??

this results in

ERROR: 
        Can't find a suitable configuration file in this directory or any
        parent. Are you in the right directory?

        Supported filenames: docker-compose.yml, docker-compose.yaml
like image 429
MiGo Avatar asked Nov 16 '20 08:11

MiGo


2 Answers

you can keep indeed multiple docker-compose files with different names(they can be completely custom) in the same directory and start them all at the same time.

Try this:

docker-compose -f docker-compose1.yml -f docker-compose2.yml up --build

The -f arguements should be before the up and then --build after.

Please note that in the case of many docker compose files these files are merged, check here for more info: https://docs.docker.com/compose/extends/#multiple-compose-files

like image 62
J-Mous Avatar answered Sep 28 '22 23:09

J-Mous


You can run the services in multiple docker-compose files using parameter -p

-p, --project-name NAME

So, the following command should work:

docker-compose -f ./docker-compose-new.yml -p new_project_name up -d

See this parameter at docs.

like image 44
Mohsen Abasi Avatar answered Sep 29 '22 01:09

Mohsen Abasi