Docker-compose - "network_mode: home" not working?

Hi,
I’m in the process of setting up Home Assistant on a NUC in docker. I’m quite new to docker so forgive me is the question is silly!
I habe Docker and docker-compose up and and running, and am running pihole and portainer successfully.
Now installing homeassistant in a container using a docker-compose.yml file for configuration:

version: '3'
services:
  homeassistant:
    container_name: homeassistant
    image: homeassistant/home-assistant:stable
    volumes:
      - ./config:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    network_mode: host

The container start and runs without errors, but HA is not accessible on port 8123…
The only way to have is working is to comment out network_mode and use a ports: statement instead:

version: '3'
services:
  homeassistant:
    container_name: homeassistant
    image: homeassistant/home-assistant:stable
    ports:
      - "8123:8123/tcp"
    volumes:
      - ./config:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
#    network_mode: host

I understand the network_mode: host method is the recommended one ? At least this is what I take from here.
So my question would be, why is it not working and should I really care?
JF

Yes you should, because without host network, discovery of your devices will not work.

I am sure HA is telling you the reason, why it fails. Check the logs.

docker logs -f homeassistant 

Thnx, al least I know I need to find out what’s happening :wink:

This is the log I get, don’t matter if I use the network_mode or ports method:

$ docker logs -f homeassistant
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] udev.sh: executing... 
[08:17:52] INFO: Setup udev backend inside container
starting version 3.2.9
[08:17:52] INFO: Update udev information
[cont-init.d] udev.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.

I don’t see any suspicious thing, and it is exactly the same in both situations.
I even desabled pihole just in case it was messing something up :wink:

I did docker inspect homeassistant. Here is an excerpt out the output:

            "NetworkMode": "host",
            "PortBindings": {},

[…]

                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null

Obviously, when using ports: these fields are populated.

Could there be some global docker or docker-compose option I’ve missed that should be on when using network_mode ?

Hi JF. Did you get anywhere with this? I have exactly the same issue

No… But must say I’ve been too busy last months on my job… Hope to finjd some time this month to look again in this…

I have exactly the same issue.
Any advance?

Check your host firewall config. It may not allow TCP port 8123 by default.

For people having this issue – please share your operating system too. Note that unless you are actually running linux, the host driver isn’t for you (as of this writing).

The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.

Source: Networking using the host network | Docker Documentation

Use the ports method instead, and as mentioned elsewhere, double check your firewall if you still have an issue.

1 Like

Oh my god… i was trying to test home assistant on mac and i couldnt access it after starting the container. I work alot with docker at work, but i couldnt figured out what i did wrong here.

Thanks alot mate! Now installing Debian VM :smile: