Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple docker-compose files - print resulting, merged docker-compose.yml

I'm running Docker compose merging multiple docker-compose-yaml files like:

docker-compose -f docker.compose.yml -f docker-compose.dev.yml -f docker-compose.X.yml -f docker-compose.Y.yml up

As it would help a lot for debugging, is it possible to print the resulting merged docker-compose-yaml file that docker-compose uses?

Simplified Example:

$ cat docker-compose.yml
> version: '3'
> 
> services:
>  nginx:
>     image: nginx:latest

$ cat docker-compose.dev.yml
> version: '3'
> 
> services:
>   nginx:
>     build:
>       context: nginx
>       dockerfile: Dockerfile

# Show merged result 
$PRINT_MERGED_DOCKERFILE_COMMAND -f docker.compose.yml -f docker-compose.dev.yml
> version: '3'
> 
> services:
>   nginx:
>     build:
>       context: nginx
>       dockerfile: Dockerfile
>     image: nginx:latest
like image 523
Wolkenarchitekt Avatar asked Jan 09 '19 19:01

Wolkenarchitekt


People also ask

How do I handle multiple files in Docker compose?

To use multiple override files, or an override file with a different name, you can pass the -f option to the docker-compose up command. The base Compose file has to be passed on the first position of the command.

Can I run multiple Docker compose files?

Using Multiple Docker Compose Files Use multiple Docker Compose files when you want to change your app for different environments (e.g., dev, staging, and production) or when you want to run admin tasks against a Compose application. This gives us one way to share common configurations.

How do I run multiple copies of compose file on the same host?

Compose uses the project name to create unique identifiers for all of a project's containers and other resources. To run multiple copies of a project, set a custom project name using the -p command line option or the COMPOSE_PROJECT_NAME environment variable.


1 Answers

Using docker-compose config will show the merged docker-compose yaml:

https://medium.com/@pscheit/docker-compose-advanced-configuration-541356d121de

docker-compose -f docker.compose.yml -f docker-compose.dev.yml config

It will also print the resulting variables that are used which is also quite helpful for debugging.

like image 160
Wolkenarchitekt Avatar answered Oct 11 '22 08:10

Wolkenarchitekt