Cannot access localhost:8123 when running in docker with network=host

Hi there. I want to run Home Assistant on my M1 Mac mini with Docker. I have it working fine when I run the container in network mode bridge and exposing port 8123, but with that configuration I was not able to use the HomeKit integration (I also tried to expose the default port for the HomeKit integration, 21603).

After looking around topics in the community it seems like I have to run the Home Assistant container in network mode host for the HomeKit integration to work properly. When I do this I get no error logs and the container looks healthy, but I cannot find the Home Assistant UI anywhere (localhost:8123 or IP:8123). I also cannot find the port using sudo lsof -i -n -P | grep 8123.

Thanks for any help!

Should be

homeassistant:8123

or

YourMacIP:8123
eg. 192.168.1.1:8123
```

Neither of these are available. If I ping them I get ping: cannot resolve (MacIP):8123: Unknown host

the actual IP address of your mac mini
Don’t think you can ping a IP:port (you can’t in windows anyway)

http://localhost:8123, http://homeassistant.local:8123 or http://(MyMacIP):8123 all gives refused to connect in my browser.

Does that work from console?

docker exec -it homeassistant /bin/bash

can you detail your install and setup abit further? You are on the macMini or ssh?
macOS or linux?
which install method did you use (docker you said) so linux os? or is there a docker image for macOS?
So plain container no supervisor?

I am on the M1 Mac mini running macOS Monterey 12.6 and use the homeassistant/home-assistant:latest image. I run the following command to start Home Assistant:

docker run -d \                                                                 
  --name homeassistant \
  --privileged \
  --restart=unless-stopped \
  -e TZ="Europe/London" \
  -v homeassistant_data:/config \
  -p 8123:8123 \
  --network=host \
  homeassistant/home-assistant:latest

Home Assistant works flawlessly and is available at localhost:8123 when I run it with:

docker run -d \                                                                 
  --name homeassistant \
  --privileged \
  --restart=unless-stopped \
  -e TZ="Europe/London" \
  -v homeassistant_data:/config \
  -p 8123:8123 \
  --network=bridge \
  homeassistant/home-assistant:latest
1 Like

Linux Docker container install docs

Hmm looks the same except for the image. Although latest and stable appear to be the same image atm. Not sure why macOS doesn’t have container instructions.

what does ifconfig show for eth0: ?? That should be the address to use.

docker run -d \
  --name homeassistant \
  --privileged \
  --restart=unless-stopped \
  -e TZ=MY_TIME_ZONE \
  -v /PATH_TO_YOUR_CONFIG:/config \
  --network=host \
  ghcr.io/home-assistant/home-assistant:stable

You could ask here too.
HA discord Install channel

I believe the host option is not working as expected on Macs.

This is stated on the ESPHome docs for running ESPHome as a docker container:

# On Docker, host networking mode is required for online status indicators
docker run --rm --net=host -v "${PWD}":/config -it esphome/esphome

# On Docker with MacOS, the host networking option doesn't work as expected. An
# alternative is to use the following command if you are a MacOS user.
docker run --rm -p 6052:6052 -e ESPHOME_DASHBOARD_USE_PING=true -v "${PWD}":/config -it esphome/esphome

Similar case: Unable to access after docker initialization in osx

2 Likes

I have tried to start home assistant container with the network_mode: host as proposed by the docker-compose.yaml examples. I’ve got an error and a warning message in the container logs which I couldn’t interpretative. By switching to network_mode: bridge I can finally access the Home Assistant UI.

I just used Docker on Mac to test how the setup works. I currently have Home Assistant OS running on an Intel Nuc want to migrate to Docker.

This helped me!!!

I uninstalled docker desktop and reinstalled only the docker engine in Ubuntu Linux.
The problem is with docker desktop it somehow closes the port.
I do not have firewall running in my ubuntu as well.
I needed to run my docker engine using sudo.

Note when you use port instead of network=host, the self discovery does not work as expected.

Hi,

On windows 10 using subsystem linux ubuntu 22.04 with docker desktop, I got same issue trying to change from bridge (thats was running ok Home assistence) to Host mode however homekit apple was not reaching it, So after try many ways I was reading in Docker desktop the configuration finding under Settings > Resources> Network>Enable host networking a simple “check”,

Blockquote Host networking allows containers that are started with --net=host to use localhost to connect to TCP and UDP services on the host. It will automatically allow software on the host to use localhost to connect to TCP and UDP services in the container. Sign in required.