Docker network: How to set up access to a DB in another container (172...) and network devices in my home network (192.168.178.0)

My docker network (on a ubuntu server with IP 192.168.178.6) uses the address range 172…

Now I have openHAB running in a docker container, connected to a MariaDB running in another container.
This works without problem.
But now I need access from the openHAB container (172.22.0.3) to my network devices with 192.168.178.x

What do I have to configure on the docker/container side and where?

Thanks a lot for your help.

You can connect from one container to another one using its container-name as DNS. So you don’t have to use the container’s internal ip-address as this may change upon a server- or container-restart.

Connecting from a container to a destination outside the docker-environment and outside the docker-host is no rocket science - just use the destination’s ip-address oder (even better) the DNS-name. Your Linux-host should route (and masquerade) as needed - at least if you haven’t screwed up your host’s firewall or your docker’s network-settings.

Thanks a lot for your fast reply.

I’ve set up two containers for openHAB 3.0. One with openHAB and the second with the required MariaDB. So called THINGS (Home Automation Devices) can’t be discovered, becaus my home network 192.168.178 is not accessible/selectable in the openHAB container. Only the 172.22.0.3/16

I’m kinda stuck here.

By default docker run ... starts the container in the default bridged-network. docker-compose creates a separate/new bridge-network for each service (= each docker-compose.yml-file)

You can run the containers in the host-network. That means the container runs as it is directly connected to the host. Each port the container opens is directly accessible from the outer network.

To do this for starting a container with docker run ... you can use this as a blueprint:

docker run --net=host -d <imagename>

Or if you are using docker-compose you can do the same - see Compose file version 3 reference | Docker Documentation

services:
  some-service:
    network_mode: "host"

At the moment my yaml.file looks like this concerning the networksettings:

version: '2.2'

services:
  openhab3:
    image: "openhab/openhab"
    container_name: openhab3
    restart: unless-stopped
    networks:
      - default

  oh3persistence-db:
    image: mariadb
    container_name: openhab3-db
    command: --transaction-isolation=READ-COMMITTED --log-bin=ROW
    ports:
      - "33306:3306"
    restart: unless-stopped

networks:
  default:

How exactly do have to change the openhab3 service section?