All containers in one file

Hello,
Suppose you need to use different services such as Apache, Nginx, MySQL, MongoDB, Node.js, etc. for a project. Some of these services must be connected to each other and others not. Is there a problem if only one YAML file is created for all these services?

Any idea welcomed.

Cheers.

A problem, no, I don’t think so as soon as you can manage the file easily.

Two weeks ago I’ve answered to one of your question and the answer was about the COMPOSE_FILE variable. On my side, I’m using a lot of yaml files (perhaps ten) and I mention them, in a specific order, in COMPOSE_FILE then let docker to “merge” them.

1 Like

Hello,
Thank you so much for your reply.
What you mean is that I can have multiple YAML files but use COMPOSE_FILE to specify the order in which they are executed. Is it true? For example:

COMPOSE_FILE=docker-compose-1.yml:docker-compose-2.yml

Which YAML file should this line be in? That file which has more priority?

Here is an example, just run

COMPOSE_FILE=composer-php.yaml:composer-apache.yaml:composer-apache_override.yaml:composer-php_override.yaml:composer-postgresql.yaml:composer-postgresql_override.yaml:composer-redis.yaml docker compose config

To understand how docker compose will “merge” files (only in memory, not on disk).

In my example, I’m using PHP, Apache, PostgreSQL and Redis. Both services are declared in their own yaml files and I’m first adding in the list the “main” file (like php) then I put the one who override it (i.e. the one who update a given node).

docker compose config will allow you to understand what will happens.

1 Like

Thanks again.
In which file did you put these above lines?

Yes, using a YAML service file to define the service like Apache, Nginx, MySQL, Node.js etc. for project is a common approach in Docker.

1 Like

Hi,
Thank you so much for your reply.
Suppose I have several YAML files and now I want to specify the order of their execution. In which YAML file should I put the following line?

COMPOSE_FILE=docker-compose-1.yml:docker-compose-2.yml

Hello

The most I read your questions, the most I think you miss prerequisites and you make a mix of a lot of things.

To your last question: no YAML files at all; it’s a command you should fired on the console. You can put such commands in a Linux script (files having .sh or .bash extensions).

1 Like