Home Assistant
Here's a docker-compose.yml for home assistant:
services:
homeassistant:
container_name: homeassistant
image: "ghcr.io/home-assistant/home-assistant:latest"
volumes:
- /apps/homeassistant/data:/config
- /etc/localtime:/etc/localtime:ro
- /run/dbus:/run/dbus:ro
restart: unless-stopped
privileged: true
network_mode: host
We're using network_mode: host here, which for the most part you won't use on your containers. HA tends to work better this way, because it simplifies discovery of other things on your network. Using this mode means the docker container is using the IP stack of the host machine, not the IP inside docker, so you don't need to do container level port forwarding. If HA is listening on a given port, so is the host machine.
On place this messes with things (a little) is the Traefik config. Because we're in host mode and not bridge mode, we can't use container labels to tell Traefik how to configure itself for HA. The fix is simple.
In your traefik folder, create a folder called 'dynamic-configs'
traefik/
├── acme.json
├── docker-compose.yaml
├── dynamic_configs
│ ├── homeassistant.yml
└── traefik.yml
Inside that folder, create a file called homeassistant.yml and paste this:
# traefik/dynamic_configs/homeassistant.yml
http:
routers:
homeassistant:
rule: "Host(`ha.beanz.com`)" # Replace with your desired domain
entrypoints:
- "websecure"
service: "homeassistant-svc"
tls:
certResolver: "letsencrypt"
services:
homeassistant-svc:
loadBalancer:
servers:
# IMPORTANT: Use your Docker host's IP address and Home Assistant's port (default 8123)
- url: "http://<docker-host-ip-address>:8123"
Modify lines 5 and 17 accordingly.