From 9f723d9026cbde021700097c1cf9a31d88b278e9 Mon Sep 17 00:00:00 2001 From: Kevin Heyer Date: Sun, 16 Mar 2025 21:16:44 +0000 Subject: [PATCH 1/2] Add Homeassistant container --- homeassistant/.env-example | 5 +++++ homeassistant/README.md | 27 +++++++++++++++++++++++++++ homeassistant/docker-compose.yml | 30 ++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 homeassistant/.env-example create mode 100644 homeassistant/README.md create mode 100644 homeassistant/docker-compose.yml diff --git a/homeassistant/.env-example b/homeassistant/.env-example new file mode 100644 index 0000000..04df6b7 --- /dev/null +++ b/homeassistant/.env-example @@ -0,0 +1,5 @@ +# Homeassistant Version (Standard: latest) +HOMEASSISTANT_VERSION=latest + +# Homeassistant Domain +HOMEASSISTANT_DOMAIN=Homeassistant.example.com \ No newline at end of file diff --git a/homeassistant/README.md b/homeassistant/README.md new file mode 100644 index 0000000..3a38a68 --- /dev/null +++ b/homeassistant/README.md @@ -0,0 +1,27 @@ +# HomeassistantDocker Deployment + +This repository provides a `docker-compose` configuration for deploying the Homeassistant container, which is accessible via Traefik as a reverse proxy. + +## Prerequisites +- Docker and Docker Compose must be installed +- Traefik must be set up as a reverse proxy + +## Installation + +1. **Configure the `.env` file** +Rename the `.env-example` file to `.env` and update the file with your specific values. This file contains environment variables used by the Traefik service. + +```bash +mv .env-example .env +``` +Modify the .env file +``` + +2. **Start Docker-Compose** + + ```sh + docker-compose up -d + ``` + +## Access +Once the container is running, Homeassistant will be available at the configured domain. \ No newline at end of file diff --git a/homeassistant/docker-compose.yml b/homeassistant/docker-compose.yml new file mode 100644 index 0000000..cc4ed39 --- /dev/null +++ b/homeassistant/docker-compose.yml @@ -0,0 +1,30 @@ +--- +services: + homeassistant: + container_name: homeassistant + image: "ghcr.io/home-assistant/home-assistant:${HOMEASSISTANT_VERSION:-latest}" + volumes: + - ./data/config:/config + - /etc/localtime:/etc/localtime:ro + - /run/dbus:/run/dbus:ro + restart: unless-stopped + privileged: true + network_mode: host + environment: + - TZ=Europe/Rome + cap_add: + - NET_ADMIN + - NET_BIND_SERVICE + - SYS_ADMIN + labels: + - "traefik.enable=true" + - "traefik.docker.network=traefik" + - "traefik.http.routers.homeassistant.entrypoints=http" + - "traefik.http.routers.homeassistant.rule=Host(`${HOMEASSISTANT_DOMAIN:?error}`)" + - "traefik.http.middlewares.homeassistant-https-redirect.redirectscheme.scheme=https" + - "traefik.http.routers.homeassistant.middlewares=homeassistant-https-redirect" + - "traefik.http.routers.homeassistant-secure.entrypoints=https" + - "traefik.http.routers.homeassistant-secure.rule=Host(`${HOMEASSISTANT_DOMAIN:?error}`)" + - "traefik.http.routers.homeassistant-secure.tls=true" + - "traefik.http.routers.homeassistant-secure.service=homeassistant" + - "traefik.http.services.homeassistant.loadbalancer.server.port=8123" \ No newline at end of file From aa34375806c8f192368ee8d003177e9b8cae0b2c Mon Sep 17 00:00:00 2001 From: Kevin Heyer Date: Sun, 16 Mar 2025 21:52:44 +0000 Subject: [PATCH 2/2] Add Homeassistant container --- homeassistant/.env-example | 2 +- homeassistant/README.md | 73 +++++++++++++++++++++++--------- homeassistant/docker-compose.yml | 9 +++- 3 files changed, 62 insertions(+), 22 deletions(-) diff --git a/homeassistant/.env-example b/homeassistant/.env-example index 04df6b7..459593e 100644 --- a/homeassistant/.env-example +++ b/homeassistant/.env-example @@ -2,4 +2,4 @@ HOMEASSISTANT_VERSION=latest # Homeassistant Domain -HOMEASSISTANT_DOMAIN=Homeassistant.example.com \ No newline at end of file +HOMEASSISTANT_DOMAIN=homeassistant.example.com \ No newline at end of file diff --git a/homeassistant/README.md b/homeassistant/README.md index 3a38a68..3ca2fd9 100644 --- a/homeassistant/README.md +++ b/homeassistant/README.md @@ -1,27 +1,62 @@ -# HomeassistantDocker Deployment +# Home Assistant Docker Setup with Traefik -This repository provides a `docker-compose` configuration for deploying the Homeassistant container, which is accessible via Traefik as a reverse proxy. +This guide provides instructions for deploying Home Assistant using Docker and Traefik as a reverse proxy. The setup includes securing the Home Assistant instance with HTTPS and configuring a trusted proxy. ## Prerequisites -- Docker and Docker Compose must be installed -- Traefik must be set up as a reverse proxy +- Docker and Docker Compose installed on your system +- Traefik configured as your reverse proxy +- A domain name pointing to your Home Assistant instance -## Installation +## Environment Variables +Before deploying the container, create a `.env` file from the provided `.env-example` file and adjust the values as needed. -1. **Configure the `.env` file** -Rename the `.env-example` file to `.env` and update the file with your specific values. This file contains environment variables used by the Traefik service. - -```bash -mv .env-example .env -``` -Modify the .env file +```sh +cp .env-example .env +nano .env ``` -2. **Start Docker-Compose** - - ```sh - docker-compose up -d - ``` +### `.env-example` file +```ini +# Home Assistant Version (Default: latest) +HOMEASSISTANT_VERSION=latest -## Access -Once the container is running, Homeassistant will be available at the configured domain. \ No newline at end of file +# Home Assistant Domain +HOMEASSISTANT_DOMAIN=homeassistant.example.com +``` + +## Starting the Container +Once the `.env` file is configured, start the Home Assistant container using: +```sh +docker-compose up -d +``` + +## Configuring the Reverse Proxy +To enable proper proxy support in Home Assistant, update `data/config/configuration.yaml` with the following settings: + +### Finding the Local Subnet IP +To determine the Docker subnet used by Home Assistant, run: +```sh +docker inspect homeassistant | grep Gateway +``` + +### `configuration.yaml` +```yaml +http: + ip_ban_enabled: true + login_attempts_threshold: 5 + use_x_forwarded_for: true + trusted_proxies: + - 10.0.0.0/24 # Local Subnet + - 172.18.0.0/24 # Your Docker Subnet +``` + +## Accessing Home Assistant +Once everything is set up, restart Home Assistant and it should be accessible via the configured domain: +``` +https://homeassistant.example.com +``` + +If there are any issues, check the container logs with: +```sh +docker logs -f homeassistant +``` \ No newline at end of file diff --git a/homeassistant/docker-compose.yml b/homeassistant/docker-compose.yml index cc4ed39..9561c31 100644 --- a/homeassistant/docker-compose.yml +++ b/homeassistant/docker-compose.yml @@ -9,7 +9,8 @@ services: - /run/dbus:/run/dbus:ro restart: unless-stopped privileged: true - network_mode: host + networks: + - traefik environment: - TZ=Europe/Rome cap_add: @@ -27,4 +28,8 @@ services: - "traefik.http.routers.homeassistant-secure.rule=Host(`${HOMEASSISTANT_DOMAIN:?error}`)" - "traefik.http.routers.homeassistant-secure.tls=true" - "traefik.http.routers.homeassistant-secure.service=homeassistant" - - "traefik.http.services.homeassistant.loadbalancer.server.port=8123" \ No newline at end of file + - "traefik.http.services.homeassistant.loadbalancer.server.port=8123" + +networks: + traefik: + external: true \ No newline at end of file