I am running docker and docker compose on my main home lab server. The server has a network card and 2 different static IPs 1 of witch are in a separate /24s then my "main" network.
I want to pass the IoT Network IP address assigned to the server (192.168.7.200) instead of the main network IP for the server (192.168.1.100).
I have a config.yaml for the compose, but I think I did something wrong. When I run:
docker-compose up -d
Everything says it worked correctly but I am not able to get to the homeassistant interface.
I can browse to the Portainer interface with the main IP (192.168.1.100:9000) and even see in the status of the homeassistant container that the network settings look correct.
When I browse to homeassistant interface (192.168.7.200:8123) nothing happens.
I think I might be creating a fake network that is clashing with the real IP of the home lab server.
Below is the .yaml file I am using.
version: '3.0'
services:
portainer:
container_name: portainer
image: portainer/portainer-ce
restart: always
ports:
- "9000:9000/tcp"
environment:
- TZ=Europe/London
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /opt/portainer:/data
homeassistant:
container_name: homeassistant
image: "ghcr.io/home-assistant/home-assistant:stable"
volumes:
- /opt/homeassistant/config:/config
- /etc/localtime:/etc/localtime:ro
restart: unless-stopped
privileged: true
networks:
static-network:
ipv4_address: 192.168.7.200
networks:
static-network:
ipam:
config:
- subnet: 192.168.7.0/24
Im new to docker other than some random edits I had to do at my old job, so please be kind lol.
I have looked around online for ways to pass ip address to the docker container, and I know that if I use:
network_mode: host
In the .yaml it will allow me to browse to the homeassistant interface with the main ip (192.168.1.100:8123), but like I said I would like to use the IoT IP address associated with the main server 192.168.7.0/24.
2
Answers
You are making another network with the
192.168.7.0/24
ip range which is overlapping with the external network.One way to avoid this is to make a network in your docker-compose which is external and create the bridge network from the command line , like this:
And manually create the network:
If something goes wrong , ask away!
Hope that helps!
For connections from outside of Docker (for example from other hosts) you configure them with
ports:
. Yourhomeassistant
container doesn’t haveports:
so it’s unreachable aside from other containers on thestatic-network
Docker network (its manual IP settings don’t matter).As @AlirezaPourchali notes in their answer, the manual
networks:
setting that sets one of the host network ranges is likely to cause conflicts. If you’re using Docker Desktop then the container network and host networks are separated enough that this probably will just cause the host network to be unreachable from the container. Compose provides adefault
network for you, and in most cases you don’t need to include anynetworks:
blocks at all in your Compose setup.You mention that you have a multi-homed host. By default
ports:
will make the container accessible on all host network interfaces (it will bind to 0.0.0.0 on the host). You can specify an alternate IP address to make it only accessible on specific interfaces if you need to. The IP address is one the host already has (on a Linux host,ifconfig
already includes it).If the container needs to know this IP address in some way, usually the best way to pass it in is via an environment variable, but it’s very dependent on the application setup how to configure and use it.