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
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With