HASS, Docker, Networking and Discovery

Hi

To start off I am new to Home Assistant and Docker. Moving from Smartthings to HASS for the control and the ability to run locally.

The environment that I am building:
i5 low power utilization, 8GB, 120GB M2 SSD
Ubuntu Server 8.04
Docker
Portainer (Docker management)
homeassistant/home-assistant
traefik (reverse proxy - Let’s Encrypt wild card cert)
eclipse-mosquitto (MQTT)
stjohnjohnson/smartthings-mqtt-bridge (access to Z-Wave – looking for a Z-Wave to MQTT bride – to run on remote Pi)
nodered/node-red-docker

The primary issue being that hass not being on the same subnet as my primary network not being able to use the built in discovery capabilities (discovery is activated in configuration.yaml). this first was noticeable when HASS did not find my Google Home Mini’s for the Google Cast functions.

When I started testing HASS I used HASS.IO (homeassistant/amd64-hassio-supervisor) on docker and it was able to conduct discovery. The HASS .IO implementation created a NIC "eno1" in its homeassistant container that is in the host network. This worked perfectly to discover items on the primary network. Unfortunately, there are other issues with the HASS .IO docker implementation and program updates and (add-on’s) that caused me to move to the mainline Home Assistant docker implementation.

I have RTFM for the discovery issue and have added --network=host to docker run but docker returns “Failure container cannot be disconnected from host network or connected to the host network”. I have also attempted to add a Google Home Mini manually into the configuration.yaml despite being able to ping it from within the container.

# Google Cast
cast:
  media_player:
    - host 192.168.250.168

Any help would be apricated

It would be nice if the homeassistant/home-assistant container had the "eno1"NIC the same as the HASS.IO implementation.

Mike

Here is a copy of my docker command that uses a non-hassio image:

docker run -d --name="home-assistant" --restart=unless-stopped -v /home/finity/docker/hass-config:/config -v /etc/localtime:/etc/localtime:ro -v /home/finity/docker/sshkey/.ssh:/root/.ssh --device /dev/zigbee:/dev/zigbee --device /dev/ttyUSB-ZStick-5G:/dev/ttyUSB-ZStick-5G --net=host homeassistant/home-assistant

Everything is discovered correctly on my install. Mine is running on a NUC running Debian 9.

You need to be using --net=host in your Docker run.

--network=host is not the correct syntax

1 Like

Thank you for your suggestion, but as the other times it tried that it did not work.

Here is my docker run:

sudo docker run -d \
 --name="hass" \
 --restart on-failure \
 --net=host \
 --network=hass-net \
 -v /home/docker/homeassistant/hass_config:/config \
 -e "TZ=America/New_York" \
 -p 8123:8123 \
 homeassistant/home-assistant

Not a docker expert (although I’m using it for HA too), but it seems as if you’ve specified a network (“hass-net”) which I think creates a seperate network just for that container. Try removing it and see if it works.

also you need to remove the “-p 8123:8123” part. You can’t have net=host and specify a port since net=host opens all the host ports to the container.

As others have mentioned, you have several problems with your run.

get rid of --network=hass-net, and -p 8123:8123 and everything should work fine.

Yes, that was correct. Removing the two entrees and adding --network=host did allow for Home Assistant discovery but I lost the ability for containers to reference each other by container name via the internal Docker DNS.

After looking around the web I found that using a network driver type of MACVLAN worked. I created a docker MACVLAN network hass-macvlan and assigned a container NIC to that network with a static local network IP. I then was able to assign the --network=hass-net to the same container.

 --network=hass-macvlan \
 --ip=192.168.250.220 \

Now I have access to Home Assistant web interface on IP 192.168.250.220 and the Docker internal network hass-net 172.20.10.1/24 for inter container communications.

Note:
Portainer 1.19 will not use MACVLAN on non-swarm containers.
You need to use 1.20dev
portainer/portainer:fix2412-macvlan-not-listed

2 Likes

Do I understand it correctly? Following these instructions, I can put HA docker (non-Hass.io) into docker’s subnet and still have ability to use discovery and communicate between devices which are outside of subnet in the same phisical LAN?

If Yes, can someone rewrite above instructions for a newbie step-by-step instruction?

I tried playing around with this, and once I start the container in net=host mode, I can’t get the UI up.

Hi,

I have used this command to install docker hass.io: hassio-build/install at master · home-assistant/hassio-build · GitHub on Raspian (RPi #B+) but now I have trouble with discovering Xiaomi Mi Box (and probably issue with Xiaomi Vacuum). After reading this troubleshooting: Removed integration - Home Assistant I came to the conclusion that I need to add “–net=host” added to the docker run.

How to do that after the setup of HA? If I will do that will I lose current instance/configuration of hass.io?

My “docker ps”:

CONTAINER ID        IMAGE                                      COMMAND                  CREATED             STATUS              PORTS               NAMES
4t8guiefsfwd        homeassistant/raspberrypi3-homeassistant   "/bin/entry.sh pytho…"   23 hours ago        Up About an hour                        homeassistant
fdecefrfewdw        homeassistant/armhf-addon-duckdns          "/run.sh"                23 hours ago        Up 23 hours                             addon_core_duckdns
5hny5ij4g3rr        homeassistant/armhf-hassio-supervisor      "python3 -m hassio"      2 days ago          Up 23 hours                             hassio_supervisor

Thanks for any help,
Viv

When you install hassio that parameter is already set.

Thanks.

I was able to discover Xiaomi Mi Box after some iptables tweaking and the Xiaomi Vacuum had different token then before.

I tried creating a home assistant install via a docker image, but if I use the
--ip=192.168.x.x
parameter, I get the following error:
docker: invalid reference format.

@dap35 I have the same issue - what am I missing?

I hadn’t looked at this in a long time, but as best I can tell, the --net=host option for docker on MacOS doesn’t work and using the -p 8123:8123 option doesn’t allow discovery to work.

1 Like

I gave up, ubuntu got me up and running. Update in case future folks find this thread

I wish I could find the original source of the solution to give credit, but…
If you want to run home assistant in a docker container without --net=host or even in a swarm and maintain the discovery functionality the solution is do the following on the host(s).

  1. Edit /etc/avahi/avahi-daemon.conf to have the following
[reflector]
enable-reflector=yes
reflect-ipv=no
  1. sudo systemctl restart avahi-daemon
  2. repeat for all nodes in swarm, if applicable

Edit: Found the source all credits go here.

1 Like

Just to confirm, Docker Desktop for OSX simply does not support --net=host (generally, not just for HA), or the macvlan network mode. This means HA on Docker on Mac is impossible to use, as discovery is broken with port mapping (-p), and docs for manual configuration of all your integrations are lacking.

Thank for the info.

I confirm this “avahi-daemon” setup makes my home Assistant in a docker with bridge network (and swag proxy) discovering my google cast devices