A. Fendt
A. Fendt

Reputation: 87

Docker inter-container communication

I'm facing a relatively simple problem here but I'm starting to wonder why it doesn't work.

I want to start two Docker Containers with Docker Compose: InfluxDB and Chronograph.

Unfortunately, the chronograph does not reach InfluxDB under the given hostname: "Unable to connect to InfluxDB Influx 1: Error contacting source"

What could be the reason for this?

Here is my docker-compose.yml:

version: "3.8"

services:
  influxdb:
    image: influxdb
    restart: unless-stopped
    ports:
      - 8086:8086
    volumes:
      - influxdb-volume:/var/lib/influxdb
    networks:
      - test

  chronograf:
    image: chronograf
    restart: unless-stopped
    ports:
      - 8888:8888
    volumes:
      - chronograf-volume:/var/lib/chronograf
    depends_on:
      - influxdb
    networks:
      - test

volumes:
  influxdb-volume:
  chronograf-volume:

networks:
  test:
    driver: bridge

I have also tried to start a shell inside the two containers and then ping the containers to each other or use wget to get the HTTP-API of the other container. Even this communication between the containers does not work. On both attempts with wget and ping I get timeouts.

It must be said that I use a Banana Pi BPI-M1 here. Is it possible that it is somehow due to the Linux that container to container communication does not work?

Upvotes: 0

Views: 1476

Answers (2)

A. Fendt
A. Fendt

Reputation: 87

The Docker service creates some iptables entries in the tables filter and nat. My OpenVPN Gateway script executed the following commands at startup:

iptables --flush -t filter
iptables --flush -t nat

This will delete the entries from Docker and communication between the containers and the Internet will no longer be possible.

I have rewritten the script and now everything works again.

Upvotes: -1

Andreas Jägle
Andreas Jägle

Reputation: 12260

If not configured, chronograf will try to access influxdb on localhost:8086. To be able to reach the correct influxdb instance, you need to specify the url accordingly using either the --influxdb-url command line flag or (personal preference) an environment variable INFLUXDB_URL. Those should be set to the value of http://influxdb:8086 which is the docker DNS name derived from the service name of your compose file (the keys one level below services).

This should do the trick (snippet):

  chronograf:
    image: chronograf
    restart: unless-stopped
    ports:
      - 8888:8888
    volumes:
      - chronograf-volume:/var/lib/chronograf
    environment:
      - INFLUXDB_URL=http://influxdb:8086
    depends_on:
      - influxdb
    networks:
      - test

Please check the chronograf readme (section Using the container with InfluxDB) for details on configuring the image and check the docker compose networking docs on some more info about networks and dns naming.

Upvotes: 2

Related Questions