Unable to add Loki as Grafana data source with Docker load balancer

I had the problem described in this ticket. In short:
I set up a Docker Swarm Stack with Loki and Grafana and got “Bad Gateway. 502” when trying to add Loki as data source in Grafana.

I could solve it by changing the stack configuration of the Loki service from:

      - "3100:3100"


      - target: 3100
        published: 3100
        mode: host

Does anyone know why its not working with the default Docker Swarm load balancer? Is there some Docker configuration necessary to make it work or is this a bug in Loki/Grafana?