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?
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.
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
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: