'Set docker-compose hostname for services with replicas

I have a simple docker-compose setup with 2 replicas, and each container needs to have a unique hostname. Is it possible to achieve this?

services:
  rmq-consumer:
    deploy:
      replicas: 2
    hostname: some-dynamic-value

It would be ideal if hostname could reference the container name, which docker-compose dynamically generates.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source