New Connection Error [Err no 111] Connection Refused

Hi everyone, I am trying to connect to Influxdb 2 but getting connection refused each time.
This is my docker compose I am using to create InfluxDB container:-

influxdb:
    image: influxdb:alpine
    volumes:
      - influxdb-data:/var/lib/influxdb
    ports:
      - "8086:8086"
    environment:
      DOCKER_INFLUXDB_INIT_MODE: setup
      DOCKER_INFLUXDB_DB: openwisp2
      DOCKER_INFLUXDB_INIT_USERNAME: openwisp
      DOCKER_INFLUXDB_INIT_PASSWORD: openwisp
      DOCKER_INFLUXDB_INIT_ORG: openwisp
      DOCKER_INFLUXDB_INIT_BUCKET: openwisp-bucket
      DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: "openwisp-secret"

For querying I am using influxdb-client(python library) and querying in a way:
INFLUXDBClient(url=" http://localhost:8086 ",token="openwisp-secret", org="openwisp").query_api().query(Query I wanna execute)

I don’t think you need the quotes around the token. Try it without them.

Thanks @kramik1 for help. I found that I have to pass container_name too in docker-compose for my tests to work well

You are trying to get 2 containers to talk to each other? In that case, you do need to use the container name since that is the default host name for the container. Is that correct?

Hello i’m facing the same issue can you explain in brief what should i do to solve the issue.