skip to Main Content

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.
Network Config Section In Portainer

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


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

    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:
          - Interface2
    
    networks:
        Interface2:
          external: true
    

    And manually create the network:

    docker network create -d bridge -o com.docker.network.bridge.host_binding_ipv4=192.168.7.200 Interface2
    
    

    If something goes wrong , ask away!
    Hope that helps!

    Login or Signup to reply.
  2. For connections from outside of Docker (for example from other hosts) you configure them with ports:. Your homeassistant container doesn’t have ports: so it’s unreachable aside from other containers on the static-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 a default network for you, and in most cases you don’t need to include any networks: blocks at all in your Compose setup.

    services:
      homeassistant:
        # container_name: homeassistant  # unnecessary
        image: "ghcr.io/home-assistant/home-assistant:stable"
        volumes:
          - /opt/homeassistant/config:/config
          - /etc/localtime:/etc/localtime:ro
        restart: unless-stopped
        privileged: true
        ports:                           # add
          - '8123:8123'                  # add
        # networks: { ... }              # remove
    # networks: { ... }                  # remove
    

    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).

    ports:
      - '192.168.7.200:8123:8123'
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search