Homeassisant in docker unreachable using network mode host

Hello everyone,
New to the community, I have been trying to install homeassistant into docker for a while. The installation was successful however I cannot access homeassistant when using port 8123 when network mode is host, I can only access it if I change it to port 8123. I am running the latest ubuntu 22.04 and freshly installed docker engine and docker desktop. I turn off the ufw firewall and also tried adding the 8123 into whitelist, still no change.

This is the running log
2022-12-06 12:02:51 s6-rc: info: service s6rc-oneshot-runner: starting
2022-12-06 12:02:51 s6-rc: info: service s6rc-oneshot-runner successfully started
2022-12-06 12:02:51 s6-rc: info: service fix-attrs: starting
2022-12-06 12:02:51 s6-rc: info: service fix-attrs successfully started
2022-12-06 12:02:51 s6-rc: info: service legacy-cont-init: starting
2022-12-06 12:02:51 s6-rc: info: service legacy-cont-init successfully started
2022-12-06 12:02:51 s6-rc: info: service legacy-services: starting
2022-12-06 12:02:51 services-up: info: copying legacy longrun home-assistant (no readiness notification)
2022-12-06 12:02:51 s6-rc: info: service legacy-services successfully started

Thanks in advance

hi
what do you mean by :
‘I cannot access homeassistant when using port 8123’
and
‘i can only access if I change it to port 8123’
isn’t clear !
do you use docker-compose? show it …
in ‘network mode: host’ you do not need to tell the port (you will use the host port (ubuntu in your case))

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

Thank you very much for your respond. I am sorry I was unclear during my post.

version: ‘3’
services:
homeassistant:
container_name: homeassistant
image: “ghcr.io/home-assistant/home-assistant:stable
volumes:
- /home/victor/smarthome/homeassistant/config:/config
- /etc/localtime:/etc/localtime:ro
restart: unless-stopped
privileged: true
network_mode: host

I am using docker compose and this is my compose file. What I mean is that when I am using that when using the compose file above I cannot reach home assistant. However when I change it to port 8123 it works please see below.

version: ‘3’
services:
homeassistant:
container_name: homeassistant
image: “ghcr.io/home-assistant/home-assistant:stable
ports:
- “8123:8123”
volumes:
- /home/victor/smarthome/homeassistant/config:/config
- /etc/localtime:/etc/localtime:ro
restart: unless-stopped
privileged: true

Thanks in advance

Are you using Docker Desktop (for Windows or Mac)? If so, you cannot use

network_mode: host

so you need to specify the port instead

ports:
 - 8123:8123
1 Like

Thanks for this insight. I’ve been having the same problem as OP and been banging my head against the wall.

  • I am using Docker Desktop for Linux (Pop_Os), as I read somewhere that that is recommended now.

  • As you stated the only way to access HA is by using bridge and exposing ports.

  • This let’s me access HA, however then it seems the “discovery” function of HA doesn’t work, and, none of my Google Speakers are accessile.

Any know workaround for this? Should I move from Docker Desktop to “regualr” docker?

thanks for any insight!

1 Like

Docker Desktop will not allow network_mode: host (as previously mentioned) which prevents mDNS from working which maybe be what’s effecting Google (I don’t use Google with HA so don’t now for sure).

You can try specifying the ports required for Google as well.

1 Like

I was in the same boat as you. The issue is that Docker Desktop runs inside its own virtual machine. host network mode with docker desktop means listening to the ports on the virtual machine, but there is nothing telling the actual physical machine to listen on those ports. I don’t know if you can get around this or not. Apparently host networking mode only works when running Docker natively on Linux machines. I just switched my machine over from using Docker Desktop to Docker Engine and host networking mode and network discovery in HA are finally working.

What’s docker engine and how do you use it instead of docker desktop?

Docker Desktop is a nice little package that wraps up a few docker components into one package, including Docker Engine, Docker Compose, a GUI, and a VM. Docker Engine is basically just the “docker” portion of the code without any additional bells and whistles. Its the core of Docker. Basically Docker Desktop runs a mini Virtual Machine that runs Docker Engine, which makes it nice for distributing to other Operating Systems, and it does some setup automatically.

Docker Engine can only run on Linux machines and is completely command line based. Basically you just install it, tell it what containers to run, and it will host them, just like Docker Desktop. One downside is it doesn’t have a GUI, so you will need to use the command line to fire up containers.

You can install Docker Compose, which is a separate, but related piece of software to be able to run the .yaml files.

I am not someone who enjoys using a terminal at all, so I actually installed a container called Portainer and used its ‘stacks’ feature to run my .yaml files. If Portainer creates a container, rather than Docker itself, it is able to manage the container via the web interface.

Difference between Docker Desktop and Docker Engine

Install Docker Engine (look at the server section, not the Docker Desktop Section)

Agh, OK, so I have been using Docker engine on my Pi.

So, if you swapped from docker desktop to docker engine, and docker engine only runs on Linux and docker desktop only runs on Mac or Windows, did you change OS as well?

This helped me!!!
I uninstalled docker desktop and reinstalled only the docker engine in Ubuntu Linux.

Thank you so much. I am all set now.
Note when you use port instead of network=host, the self discovery does not work as expected.