I am raising 2 mysql containers. One in the links section is writing mysql2, and the other is corresponding. mysql1. But the docker doesn’t like cyclic communication. How it to settle?

  • yml code yml . Only without passwords and IP . - Kosta B.

1 answer 1

"inside" one network, containers see each other

An example of docker-compose.yml :

 version: "3" services: mysql1: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: root mysql2: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: root 

docker-compose creates a network by default, but you can also specify network parameters manually

We start containers

 docker-compose up 

Now you can check (open in another terminal)

 # перейдем в оболочку первого (запущенного) контейнера docker-compose exec mysql1 bash # и подключимся ко второму контейнеру к mysql серверу mysql -uroot -proot -hmysql2 

The same works the other way around. Docker prescribes the matching names in the / etc / hosts file of each container.

If you need to connect from different stacks, you can create a separate network or "set" the port out to the host IP. The choice of the optimal solution depends on the task we are trying to solve.

The --link flag --link obsolete and not recommended for use . Description for network bridges in Docker.