Skip to main content

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. 

OnOne 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. 

At this point, you should be able to run 

dc up -d

Give it a couple of minutes and you can reach home assistant on http://<docker-host-IP>:8123

If you have done the DNS records and modified the homeassistant.yml file in the Traefik dynamic config directory, you can also reach HA at https://ha.beanz.com

Job's a good-un. 

Any issues with connecting to HA, follow the container logs with:

dcf (the alias we created before)
or
docker compose logs -f