H
H
HighMan2021-02-19 21:40:11
Docker
HighMan, 2021-02-19 21:40:11

How to ensure the interaction of docker containers?

Hello comrades!
I deleted the previous question completely, because ... An incorrectly asked question leads to an unnecessary answer.
Now the question is: how to ensure the interaction of containers?
There is a container with an application. In my case nextcloud, there is a container with a database, and a container with a database. These are different containers that live in different directories (on the host) and run via docker-compose.
Through docker-exec, I climbed into the nextcloud container, installed ping in it and tried to somehow dope to the container with the database. In vain!
I will give a docker-compose container with MySQL

version: '3'
services:
  mysql_server:
    container_name: mysql_server
    image: mysql:latest
    ports:
      - 3306:3306
    environment:
      - MYSQL_ROOT_PASSWORD=password

    volumes:
      - mysql_db=/var/lib/mysql

How will this container be reached? ping mysql_server does nothing.
ping: mysql_server: Name or service not known
Just in case. How can I access some network service of the host machine from the container?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HighMan, 2021-02-20
@HighMan

Thanks a lot for the informative replies. You helped me a lot! :)
Summing up the experience:
All containers launched via docker-compose.yml are in the same virtual network and perfectly see each other by name.
Some complications arise when it requires an "external" container to run from another docker-compose.yml. By default, it is in a different virtual network and does not see other containers by name.
An explicit network declaration comes to the rescue.

networks:
  pgsql_net:
    name: pgsql_net

Because The database can be used by other containers, then with it (in its docker-compose, yml) you need to declare a new grid. In my case it is called pgsql_net. All dependent containers will be .... I don’t know how to say correctly, like, to see this virtual network to declare it as external.
Here is a snippet of another docker-compose.yml that should talk to the data language.
networks:
  my_net:
    external:
      name: pgsql_net
..................
     networks:
        -my_net

In each dependent container, it is also necessary to register a network common to all containers, in this case, my_net. This my_net network will also see a separate database container network.
Perhaps somewhere I came up with something superfluous, but as a result, everything worked for me. Finally, I saw a separate container with a database.
The ability to get into a running container also helps a lot:
docker exec -it name_container /bin/bash
After that, you find yourself inside a running container and can install ping and other test tools for the lifetime of the container. If you have catalogs with a database forwarded through volume, then you can create a database and a user. This will then be stored on the host machine.
If anyone is interested, I'll post compose files and a couple of scripts to create nextcloud+onlyoffice+postgres.
I understand that for a docker specialist this is hysterical laughter, but I lost almost a day to launch all this shady stuff.
If anyone is interested, then here is the link docker-onlyoffice-nextcloud
In the code at the link, it is used nedaskul and it is highly recommended to fasten a normal database. MySQL or PostgreSQL.
Oh yes! After the first login, you need to run set_configuration.sh on the host machine. It will set up a link between nextcloud and onlyoffice.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question