Dock container hostname with dock

I have several services running each database mysql. I use docker-composeto deploy my applications in docker. I need all these services to be on the same network. For each service, I use different files to create dockers.

My problem: How can I forbid to name the same name (in docker dns) if they have the same name in different build files.

Exemple:

service1.yml

version: '2'
services:
  mysql:
    image: "mysql"
    network:
      - anetwork
[...]

service2.yml

version: '2'
services:
  mysql:
    image: "mysql"
    network:
      - anetwork
[...]

These two files are in separate folders. After starting all docker layouts. Containers are displayed with docker ps. On the name service1_mysql_1, and another service2_mysql_1. But when I write mysqldns name inside the network anetwork, both answer ...

How can I fix this? Am I using bad methods?

: -

+4
1

, :

  • , , , , , :

    version: '2'
    services:
      mysql1:
        image: "mysql"
    [...]
    
  • , .. service1_mysql_1 service2_mysql_1. , , , container_name:

    version: '2'
    services:
      mysql:
        image: "mysql"
        container_name: my-service1-mysql
    [...]
    

    , anetwork, my-service1-mysql

+1

Source: https://habr.com/ru/post/1695608/


All Articles