Can I Use Host Network Mode for Home Assistant and Still Connect Caddy?

0
50
Asked By CuriousCoder92 On

I'm trying to keep the number of exposed ports to a minimum, so most of my containers, including Caddy, use a Docker network. However, I've heard that services like Home Assistant benefit from using `network_mode: host`.

I need to access Home Assistant through a reverse proxy, meaning Caddy needs a way to communicate with Home Assistant. Here are the configurations for both containers I'm working with:

Caddy:
```yaml
image: caddy
networks:
- caddy
ports:
- "80:80"
- "443:443"
```

Home Assistant:
```yaml
image: homeassistant
cap_add:
- NET_ADMIN
- NET_RAW
network_mode: host
```

Is it even possible to set this up considering how Docker networking works? If so, what's the simplest way to achieve this? Normally, Caddy can reach other containers by their names, but I'm not sure how this setup plays out.

5 Answers

Answered By HomeHelper19 On

Have you noticed any devices that won't function with this setup? I was concerned about using my router integration for connected devices. I did manage to get my Caddy configuration working with a bit of tweaking—check out this link for some tips!

Answered By ConfigMaster42 On

Here's how I set up Home Assistant to be reverse proxied by Caddy without using host networking. I just put all my containers in the same Docker network:
```yaml
homeassistant:
image: homeassistant/home-assistant:stable
restart: unless-stopped
environment:
- TZ:${TZ}
volumes:
- $BASE_PATH/homeassistant:/config
networks:
- homeassistant-net
- caddy
```

It works well as long as everything is in the same network!

Answered By DockerDiva01 On

Since Docker defaults to `network_mode: bridge`, it isolates containers from the host network. This means Home Assistant won't be able to discover devices on the LAN unless it uses the host's network stack. If you go with `network_mode: host`, it could solve the discovery issue, but consider if that’s the best approach for your setup.

Answered By NetworkNinja88 On

To wrap your head around this, it's important to understand how network namespaces work. Using `network_mode: host` means that Home Assistant's container runs directly in the host's network namespace. For Caddy to communicate with it, you'd essentially need to bridge it to the host's network, which complicates things since containers are usually isolated in their own namespaces. Still, Caddy can proxy to software running on the host, but you may need to tweak your Caddy configuration a bit to get it right.

Answered By TechieTabs On

Just a heads up! Some folks from the Home Assistant community recommend running it as a full Virtual Machine or on bare metal instead of in a container. They say it tends to be more reliable. You can find more info on that on their installation page.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.