A lot of folks ask how to get started on a Docker stack and what to use to manage it all, so I figured I could share my docker-compose file for everyone to dig through and modify to your liking.
There are plenty of writeups on how to get Docker running on your platform, but I recommend using the official documentation from the Docker website. I assume most of you might use Ubuntu, so here are the instructions for Ubuntu
A few notes about it:
- On my docker host (Intel NUC, 8GB RAM, 256GB Samsung Evo m.2, running Alpine Linux), I have a directory
/srv/docker
where I store all persistent data for all my containers. - I use Portainer for a ‘GUI’ for my Docker stack
- If you don’t have any Ubiquiti gear, obviously the UNIFI container is worthless to you.
- My Home Assistant is storing data in PostgreSQL, and I have a flow in my Node Red that also copies some events to the Mongo database (for me to play with later on another project)
- I am using InfluxDB so I can feed Grafana (Chronograf is really just there for me to play with)
My workflow consists of:
- syncthing running in a container, pointing to my hass-config directory, where all my home assistant configuration files are, and I have syncthing running on my desktop, laptop, and NAS so I can keep versions, as well as being able to edit files locally on my computer, or while I am away on my laptop.
- config changes are synced across almost instantly, and whenever I am done, I just restart my container using either Portainer or HA-Dockermon script in HASS
Once you have a docker compose file created, you can just type docker-compose up -d
to start it all up.
I hope this helps some of you get started and takes some of the mystery out of a Home Assistant Docker stack. While this is not a comprehensive tutorial, or considered the ‘correct way’ to do anything, this has been working well for me for coming up on 8 months (many months of just running a couple of containers to figure out what I wanted the end product to look like)
In case you are wondering about the load on my NUC:
My Docker-Compose.yaml:
version: '3'
services:
portainer:
container_name: portainer
image: portainer/portainer
volumes:
- /srv/docker/portainer:/data
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "9000:9000"
unifi:
container_name: unifi
restart: unless-stopped
image: linuxserver/unifi
volumes:
- /srv/docker/unifi:/config
environment:
- PGID=0
- PUID=0
- ES_JAVA_OPTS='-Xms2g -Xmx2g'
ports:
- "8080:8080"
- "8081:8081"
- "8443:8443"
- "8843:8843"
- "8880:8880"
- "3478:3478"
syncthing:
container_name: hass-sync
restart: unless-stopped
image: linuxserver/syncthing
volumes:
- /srv/docker/syncthing:/config
- /srv/docker/hass-config:/sync
- /etc/localtime:/etc/localtime:ro
network_mode: host
environment:
- PGID=0
- PUID=0
mqtt:
container_name: MQTT
restart: unless-stopped
image: eclipse-mosquitto
volumes:
- /srv/docker/mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf
- /srv/docker/mosquitto/log:/mosquitto/log
- /srv/docker/mosquitto/data:/mosquitto/data
- /etc/localtime:/etc/localtime:ro
ports:
- "1883:1883"
- "9001:9001"
mongo:
container_name: mongo
restart: unless-stopped
image: mongo
volumes:
- /srv/docker/mongo:/data/db
- /etc/localtime:/etc/localtime:ro
ports:
- "27017:27017"
hadockermon:
container_name: ha-dockermon
restart: unless-stopped
image: philhawthorne/ha-dockermon
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /srv/docker/ha-dockermon:/config
ports:
- "8126:8126"
postdb1:
container_name: postdb1
restart: unless-stopped
image: postgres:9.6
volumes:
- /srv/docker/postgresql:/var/lib/postgresql/data
- /etc/localtime:/etc/localtime:ro
environment:
- POSTGRES_USER='myusername'
- POSTGRES_PASSWORD='mypassword'
ports:
- "5432:5432"
influxdb:
container_name: influxdb
restart: unless-stopped
image: influxdb
volumes:
- /srv/docker/influxdb/influxdb.conf:/etc/influxdb/influxdb.conf:ro
- /srv/docker/influxdb/db:/var/lib/influxdb
environment:
- INFLUX_GRAPHITE_ENABLED='true'
ports:
- "8086:8086"
grafana:
container_name: grafana
restart: unless-stopped
image: grafana/grafana
depends_on:
- "influxdb"
volumes:
- /srv/docker/grafana:/var/lib/grafana
ports:
- "3000:3000"
chronograf:
container_name: chronograf
restart: unless-stopped
image: chronograf
depends_on:
- "influxdb"
volumes:
- /srv/docker/chronograf:/var/lib/chronograf
ports:
- "8888:8888"
speedtest:
container_name: speedtest
restart: unless-stopped
image: atribe/speedtest-for-influxdb-and-grafana
depends_on:
- "influxdb"
volumes:
- /srv/docker/speedtest/config.ini:/src/config.ini
homeassistant:
container_name: home-assistant
restart: unless-stopped
image: homeassistant/home-assistant
depends_on:
- "influxdb"
- "postdb1"
devices:
- /dev/ttyACM0:/dev/ttyACM0
volumes:
- /srv/docker/hass-config:/config
- /etc/localtime:/etc/localtime:ro
- /srv/docker/hass_media:/media
network_mode: host
privileged: true
nodered1:
container_name: node-red-1
restart: unless-stopped
image: nodered/node-red-docker
depends_on:
- "homeassistant"
user: root
volumes:
- /srv/docker/node-red-1/user:/data
- /etc/localtime:/etc/localtime:ro
ports:
- "1880:1880"