Good day.

There is an idea to deploy two services in a docker on the same host using DBMS, which can also be deployed in a docker.

If you solve the task without a docker, then a single DBMS service would be raised on the host, two databases created (one for each target service), two users, one for each created database, a DBMS would be exposed to the outside port (3306 for MySQL and 5432 for postgres), and the target services would be configured to connect to the corresponding database.

I try to solve the same problem with the help of docker (specifically with the help of docker-compose). In all examples, a single DBMS and one service using a DBMS via a link are described in docker. It seems that, if necessary, raising two services using the same DBMS, for each service you need to raise two instances of the DBMS service.

Of course, when creating a docker container for a DBMS service, it is possible to prescribe code that creates databases and users with psql, but nowhere on the Internet have such examples / descriptions / recommendations been found, which is why I get the impression that I want something strange and nobody does.

  1. Do I understand correctly that raising several services of the same DBMS on one host is the norm?
  2. And otherwise, if you still should not create several DBMS services on one host, how should this problem be solved?

Please help find the answers to these questions.

  • connection between containers - aleksandr barakin
  • if your two services are not interconnected, then it is normal to use two different containers with a base for each service. The advantage of this solution - in which case - the service is easy to transfer to another machine (and this is the main plus of the docker). - KoVadim

1 answer 1

If both services do not depend on business logic from each other through the database, then it is better to organize two separate clusters (two different docker-compose.yml).

As a result, two separate containers with a DBMS will work on the host. In this way, the lack of connectivity of services can be achieved.

For the docker, it makes no difference what is in the container (application server, DBMS, etc.); for him, these are all containers that interact with each other.

PS if there are restrictions on resources on the host, then no one forbids you to use one database for two services (this will help save on the overhead resources for raising a separate database)

  • But after all, in the case of a single DBMS, both servers will have to launch one container from the DBMS, and not two personal containers of the DBMS, one for each server. - Max A Mazin
  • Yes that's right. I described the case if the services do not use shared data. In one container - one DBMS process. - Ruslan Masgutov
  • For the question itself: 1 - yes, this is the norm, because the container does not disclose the details of the contents. Communication between the host container, the container container is carried out only through the network interface. - Ruslan Masgutov
  • Actually, the question is more about how detrimental to productivity is to keep two DBMS services on the same host, for example Postgres? If the presence of two DBMS services on one host is undesirable, it turns out that for each service it is necessary to allocate its own host. - Max A Mazin
  • The question of server resources. Naturally, each container will consume part of the processor time, RAM and disk. But practice shows that such overhead resources are usually small compared to non-optimized applications or sql queries, when the query fully loads the processor and disk. - Ruslan Masgutov