Cadvisor fails to send metrics to influxdb

I am runing a docker swarm on 2 ec2 instances.
docker compose I use:

version: "3.2"
services:
    cadvisor:
        image: google/cadvisor
        hostname: '{{.Node.ID}}'
        command: -logtostderr -docker_only -storage_driver=influxdb -storage_driver_db=cadvisor -storage_driver_host=influxdb:8086
        volumes:
            - /:/rootfs:ro
            - /var/run:/var/run:rw
            - /sys:/sys:ro
            - /var/lib/docker/:/var/lib/docker:ro
        deploy:
            mode: global
    webserver:
        image: nginx
        ports:
            - "8089:80"
        logging:
            driver: fluentd
            options:
                fluentd-address: 127.0.0.1:24224 # this is the port published by the fluentd service below
                fluentd-async-connect: 1
                tag: httpd.nginx

    fluentd:
        image: papirkurvendk/fluentd-influxdb
        volumes:
            - fluentd:/fluentd/log
        ports: # needs to be exposed for the logging driver to have access
            - "24224:24224"
            - "24224:24224/udp"

    influxdb:
        image: influxdb
        volumes:
            - influx:/var/lib/influxdb
        deploy:
            mode: replicated
            replicas: 1
            placement:
                constraints:
                - node.role == manager

    grafana:
        image: grafana/grafana:5.3.4
        ports:
            - 0.0.0.0:3000:3000
        volumes:
            - grafana:/var/lib/grafana
        deploy:
            mode: replicated
            replicas: 1
            placement:
                constraints:
                - node.role == manager

volumes:
    influx:
        driver: local
    fluentd:
        driver: local
    grafana:
        driver: local

I have a problem with the cadvisor , it cannot write to the influxdb. even though they are on the same swarm and it should see the service running and it should be able to communicate with it, it still fails.

failed to write stats to influxDb - Post http://influxdb:8086/write?consistency=&db=cadvisor&precision=&rp=: dial tcp 10.0.6.5:8086: i/o timeout

I am able to go into the container and run ping influxdb and it works well, this means it sees it.

I have checked the security groups and allowed communication port 8086.

do you have any ideas why it doesn’t work ?