Simple HomeAssistant docker-compose setup
First, create a directory where HomeAssistant will reside. I use /opt/homeassistant
.
Create docker-compose.yml
:
services:
homeassistant:
container_name: homeassistant
restart: unless-stopped
image: ghcr.io/home-assistant/home-assistant:stable
network_mode: host
privileged: true
environment:
- TZ=Europe/Berlin
volumes:
- ./homeassistant_config:/config
depends_on:
- mosquitto
mosquitto:
image: eclipse-mosquitto
network_mode: host
volumes:
- ./mosquitto_conf:/mosquitto/config
- ./mosquitto_data:/mosquitto/data
- ./mosquitto_log:/mosquitto/log
Now start homeassistant so it creates the default config files:
docker-compose up
Once you see
homeassistant | [services.d] done.
Press Ctrl+C to abort.
Now we’ll create the Mosquitto MQTT server config file in mosquitto_conf/mosquitto.conf
:
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
listener 1883
## Authentication ##
allow_anonymous false
password_file /mosquitto/config/mosquitto.passwd
Now create the mosquitto password file and fix the permissions using
touch mosquitto_conf/mosquitto.passwd
chown -R 1883:1883 mosquitto_conf
We can now start create the homeassistant
mosquitto user using
docker-compose run mosquitto mosquitto_passwd -c /mosquitto/config/mosquitto.passwd homeassistant
Enter a random password that will be used for the homeassistant
user
Now we can edit the homeassistant config homeassistant_config/configuration.yml
. This is my config - ensure to insert the random MQTT password we used before instead of ep2ooy8di3avohn1Ahm6eegheiResh
:
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
http:
use_x_forwarded_for: true
trusted_proxies:
- 127.0.0.1
ip_ban_enabled: true
login_attempts_threshold: 5
mqtt:
broker: "127.0.0.1"
username: "homeassistant"
password: "ep2ooy8di3avohn1Ahm6eegheiResh"
# Text to speech
tts:
- platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
Now we can start the server using
docker-compose up
You can also use our script to generate a systemd service to autostart the docker-compose config on boot:
curl -fsSL https://techoverflow.net/scripts/create-docker-compose-service.sh | sudo bash /dev/stdin
Now login to the web interface on port 8123
and configure your HomeAssistant!