[SOLVED] Openhab container can't communicate with influxdb container

Hi folks,

It’s my first time I’m playing with docker, so be patient :slight_smile:

I’ve openhab installed in a docker container with network_mode: host
I’ve influxdb installed in a docker container, network “backend”

I’m trying to find a way to permit the communication between them.

Here my influxdb.cfg:

url=http://influxdb:8086

They are not able to reach each other, because (I suppose) they are on different networks and “influxdb” means nothing for the host network.

Here my docker-compose.yml


version: '3'

services:
  openhab: #name of the service
    container_name: jarvis
    image: "openhab/openhab:milestone-debian"
    restart: always
    network_mode: host
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/TZ:/etc/timezone:ro"
      - "./openhab_addons:/openhab/addons"
      - "./openhab_conf:/openhab/conf"
      - "./openhab_userdata:/openhab/userdata"
#      - ".java:/openhab/.java"
    environment:
      USER_ID: "1036"
      OPENHAB_HTTP_PORT: "8080"
      OPENHAB_HTTPS_PORT: "8443"
      EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Rome"
      LC_ALL: "en_US.UTF-8"
      LANG: "en_US.UTF-8"
      LANGUAGE: "en_US.UTF-8"
      CRYPTO_POLICY: "unlimited"
#    devices:
#      - "/dev/ttyACM0:/dev/ttyACM0" # for Zwave stick

Any suggestion?

thanks
Andrea

You have correctly answered your own question. Docker creates its own network to allow communication between containers. By setting networking to host, you tell docker to link the container’s network interface directly to the host machine’s, excluding it from the docker network.

You can map all the ports you need accessible and tell the container to use backend to get what you want. This is how I have mine setup so I have a minimum attack surface on the server.

I can’t give you exact examples because I’m on my phone, but have a look at the ports section of the docker-compose file reference.
You’ll want to map "8443:8443" and probably "8080:8080" as well.

1 Like

When you are on network host mode you can’t / don’t have to do a port mapping.

If your influx is running in a internal docker network you have to do a port mapping for that container to make sure that port 8086 is an external port (known in your host network)

In your influxdb.cfg your should change the url to http://localhost:8086/, http://127.0.0.1:8086/ or http://“YourHostIp”:8086/

1 Like

Thanks @avdlee it works now.

I’m a bit concerned about security (a container in backend exposed to host network), but I don’t think there are too many options …maybe some security config I’m not aware of?

Andrea

As long as it’s a “official” container, delivered by a trusted party, it shouldn’t be any more unsafe than a regular installation outside of docker.