1

I have been using a docker compose file to run a development environment for a microservices architecture that in production is deployed to kubernetes, so I use links to map k8s provided domain names to the compose service names. e.g

links:
      - "kafka:kafkadc-c44b-44.default.svc.cluster.local"

All works well when using docker-compose. But when using the new docker compose (note no hyphen), the containers are unable to comminicate with eachother. Kafka connections fail. HTTP requests fail.

Are there any changes between the docker cli version of compose, and the old docker-compose command. I cann't see a version of docker compose without the hypen, but with I have the following version information:

docker-compose version 1.29.0, build 07737305
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1h  22 Sep 2020
AndyRyan
  • 1,500
  • 12
  • 23
  • It seems like links is [deprecated](https://stackoverflow.com/questions/35832095/difference-between-links-and-depends-on-in-docker-compose-yml) and machines linked via the network option are automatically linked. – forgetso Apr 28 '21 at 10:18
  • I read this too, but the documentation on networks seems slim. I don't see a way to be able to apply network aliases beyond possibly running my own DNS, which id rather avoid. – AndyRyan Apr 29 '21 at 10:59
  • 1
    I [managed](https://github.com/forgetso/bindays/blob/master/docker-compose-prod.yml) to get my machine speaking to each other using networks. The network alias was a case of setting `hostname` – forgetso Apr 29 '21 at 11:20
  • Absolute legend, wasn't aware of the hostname parametre. Mind popping that in an answer so I can mark it as a solution? – AndyRyan Apr 29 '21 at 11:43
  • No worries, added. I can't even find the `hostname` stuff in the docs. – forgetso Apr 29 '21 at 12:58

1 Answers1

1

You can use hostname to specify a hostname for the container within its network or you can use an alias if you need a hostname per network.

e.g.

  db:
       image: mysql:5.7
       container_name: mycontainername
       hostname: myhostname
       networks:
           default:
                aliases:
                   myalias
forgetso
  • 2,194
  • 14
  • 33