How to address container for logging using docker-compose?

A container described in docker-compose.yml uses logging extension to send log to a fluentd container.

version: "2"

services:

  fluentd:
    image: fluent/fluentd:v0.14.8
    container_name: fluentd

  nginx:
    image: nginx:1.11.5
    container_name: nginx
    links:
      - fluentd
    logging:
      driver: fluentd
      options:
        fluentd-address: fluentd:24224

But this configuration does not work, as the fluentd-address is seen externally by the host (aka the host) and not from within the nginx container.

So it requires a way to know the IP address of container outside the container but in a compatible way for docker-compose, any idea ?

Use the ports option to expose a port for the logging daemon, and use the host’s IP address (or localhost, since the Docker daemon is interpreting it).

(You’ll need a ports option for your nginx container too. The Docker-assigned private IP address isn’t particularly useful for most things.)

I am running a docker swarm and exposed the port/udp. However sending messages to localhost does not work whereas 0.0.0.0 works. Any idea why?

Look at this example, how the fuentd can be used for logging aggregation using docker-compose in Docker SWARM mode