Skip to content

fw-abe/docker-practice

Repository files navigation

docker-practice

Much of this is generated by ChatGPT

Why are there multiple docker-compose.yml files?

When you run FILE_ARGS=(-f docker-compose.yml -f docker-compose.dev.yml) and then use this variable to run docker-compose "${FILE_ARGS[@]}" build, docker-compose will read both files docker-compose.yml and docker-compose.dev.yml and will use the last file read to overwrite any previous defined services, networks, and volumes.

It means, the service, network and volume definitions in docker-compose.dev.yml will overwrite any matching keys in docker-compose.yml.

For example, if docker-compose.yml contains a service named web and docker-compose.dev.yml also contains a service named web with a different configuration, the web service in docker-compose.dev.yml will be used, overwriting the one in docker-compose.yml.

It's important to keep in mind that if there are any values in docker-compose.dev.yml that are not defined in docker-compose.yml, they will be added to the final configuration.

It's a way to have a base configuration in docker-compose.yml and add or override some values in different environment files like docker-compose.dev.yml, docker-compose.prod.yml etc.