Docker container host name cannot be resolved inside docker network

In my swarm docker-compose file I am creating 7 replicas of apache storm supervisor as shown here.

storm_supervisor:
  image: storm:2.0.0
  deploy:
    replicas: 7
  command: storm supervisor
  networks:
    - my_network
  hostname: "stormsupervisor{{.Task.Slot}}"

However the hostname that I am setting is not being resolved anywhere within the swarm network. i.e. when I exec into the zookeeper container running on the same swarm network, I cannot ping “stormsupervisor1, “stormsupervisor2, etc. Instead I can only ping them by their respective container id. I can also ping using the service name (storm_supervisor), but that only returns one of the containers

Source: StackOverflow