Run Home Assistant Add-ons in Docker Compose
In this article
Running Home Assistant add-ons in a Docker Compose setup gives you the same functionality as the official add-on store, but with full control over versions, networking, and resource limits. You manage everything from a single docker-compose.yml file, which makes your setup reproducible and easy to back up. This guide assumes you already have Docker and Docker Compose installed, and that you are comfortable editing YAML files and using the command line.
What You'll Need
- A working Docker installation (version 20.10 or later recommended).
- Docker Compose (either the standalone
docker-composeor the newerdocker composeplugin). - Basic knowledge of YAML syntax and how to navigate your terminal.
- Optional but helpful: a text editor with YAML support (VS Code, Sublime, etc.).
- Access to the internet to pull images from Docker Hub or GitHub Container Registry.
Step-by-Step
- Create a directory for your setup. Choose a location that is easy to find, for example
~/homeassistant. Inside it, create a subdirectory for each add-on you plan to run, like~/homeassistant/zigbee2mqttor~/homeassistant/esphome. This keeps configuration files organized. - Write the base
docker-compose.ymlfile. Start with a simple version that defines a service for Home Assistant Core itself. Use the officialghcr.io/home-assistant/home-assistant:stableimage. Mount your configuration directory and the Docker socket if you need the Supervisor or other add-ons to interact with Docker. A minimal example looks like this:version: '3.8' services: homeassistant: container_name: homeassistant image: ghcr.io/home-assistant/home-assistant:stable volumes: - ./config:/config - /etc/localtime:/etc/localtime:ro restart: unless-stopped privileged: true network_mode: hostNote:privileged: trueandnetwork_mode: hostare often required for add-ons that need direct hardware access or broadcast/multicast networking. If you don't need those, you can omit them, but many add-ons expect them. - Identify the Docker image for your add-on. Most official add-ons are published as Docker images on GitHub Container Registry (GHCR). For example, Zigbee2MQTT is available as
ghcr.io/zigbee2mqtt/zigbee2mqtt. Check the add-on's documentation to find the correct image name and tag (e.g.,latest,stable, or a version number). - Add the add-on as a separate service. In the same
docker-compose.yml, add a new service for each add-on. For Zigbee2MQTT, it might look like:zigbee2mqtt: container_name: zigbee2mqtt image: ghcr.io/zigbee2mqtt/zigbee2mqtt:latest volumes: - ./zigbee2mqtt-data:/app/data - /run/udev:/run/udev:ro environment: - TZ=America/New_York devices: - /dev/ttyUSB0:/dev/ttyUSB0 restart: unless-stopped network_mode: hostAdjust the volume paths and device mappings to match your hardware and configuration. - Configure networking carefully. If you use
network_mode: host, the add-on shares the host's network stack. This is the simplest approach for most add-ons because they can discover devices on your LAN and communicate with Home Assistant via localhost. If you prefer bridge networking, you must explicitly map ports and set theHASS_URLorMQTT_URLenvironment variables so the add-on can reach Home Assistant. - Set environment variables. Many add-ons require configuration via environment variables rather than a config file. For example, Mosquitto (MQTT broker) needs usernames and passwords. Read the add-on's documentation and add the necessary variables under the
environmentkey. Always include theTZvariable to ensure correct time handling. - Mount configuration files. Some add-ons expect a configuration file (like
configuration.yamlfor ESPHome). Create the directory on your host and mount it as a volume. For example,./esphome-config:/config. This way you can edit the config file on your host and the add-on will see the changes after a restart. - Start the stack. Run
docker compose up -dfrom the directory containing yourdocker-compose.yml. This pulls the images and starts the containers. Check the status withdocker compose ps. - Verify that Home Assistant discovers the add-on. If you are using the Home Assistant Core container (without Supervisor), you won't see add-ons in the UI. Instead, you interact with each add-on via its own web interface or API. For example, Zigbee2MQTT has a web dashboard on port 8080 by default. Open that port in your browser to confirm it's running.
- Set up automatic restarts and updates. Use
restart: unless-stoppedto ensure containers restart after a reboot or crash. To update an add-on, pull the new image withdocker compose pulland then recreate the container withdocker compose up -d.
Common Mistakes
- Using the wrong image name. Some add-ons are not on Docker Hub; they are only on GHCR. Double-check the exact repository path from the add-on's official docs.
- Forgetting to mount the Docker socket. If you want Home Assistant to manage add-ons via the Supervisor, you must mount
/var/run/docker.sockinto the container. Without it, the Supervisor cannot start other containers. - Misconfiguring device access. For USB devices like Zigbee sticks, you must specify the correct device path. The path can change after a reboot, so consider using a symlink like
/dev/serial/by-id/...instead of/dev/ttyUSB0. - Using bridge networking without port mappings. If you don't use
network_mode: host, you must expose the necessary ports withports:or the add-on won't be reachable. - Ignoring environment variables. Many add-ons will not start if required environment variables are missing. Always read the documentation.
Tips
- Use a separate volume for each add-on's data. This prevents data loss when you update the container image. For example,
./zigbee2mqtt-datashould only contain Zigbee2MQTT's data. - Pin versions. Instead of using
latest, pin a specific version tag (e.g.,1.30.0) to avoid unexpected breaking changes. Update deliberately. - Keep your compose file in version control. This allows you to track changes and roll back if something breaks.
- Use a .env file for secrets. Store passwords and tokens in a
.envfile and reference them with${VAR}in your compose file. This keeps sensitive data out of the main file. - Test with a dry run. Use
docker compose configto validate your YAML and see the final configuration before starting.
Troubleshooting
- Container exits immediately. Check the logs with
docker compose logs <service-name>. Common causes: missing environment variables, incorrect device paths, or permission issues. Look for error messages like "device not found" or "connection refused". - Add-on cannot connect to Home Assistant. If you are using host networking, ensure Home Assistant is listening on port 8123 and the add-on is configured to use
http://localhost:8123. If using bridge networking, set theHASS_URLto the host's IP address and port. - USB device is not visible. Run
ls -l /dev/ttyUSB*on the host to see the actual device name. If the device is not there, you may need to install USB drivers or use a different port. Also check that the user running Docker has permission to access the device (add the user to thedialoutgroup). - Port conflicts. If you use host networking, the add-on uses the same ports as the host. If another service is already using that port, the add-on will fail to start. Change the add-on's port in its configuration or use bridge networking with a different host port mapping.
- Changes to config files not picked up. Some add-ons cache configuration. Restart the container after editing the mounted config file. Also ensure the file permissions allow the container to read it.
- Docker Compose command not found. If you have Docker installed but not Compose, install the plugin or use the standalone binary. On Linux, you can install it via your package manager or download from the official Docker GitHub releases.
Frequently Asked Questions
Do I need Home Assistant Supervisor to run add-ons in Docker Compose?
No. You can run each add-on as a standalone container and connect it to Home Assistant Core using MQTT or the REST API. You lose the one-click install and unified UI, but you gain flexibility.
Can I use the same add-on configuration as the official add-on store?
Mostly yes. Add-ons often use the same configuration files and environment variables. However, the Supervisor provides some automatic setup (like creating users for Mosquitto) that you must do manually in Docker Compose.
How do I update an add-on?
Run docker compose pull <service-name> to fetch a new image, then docker compose up -d <service-name> to recreate the container with the new image. Your data volumes remain intact.
Is it safe to use privileged: true?
It grants the container full access to the host, which is a security risk. Only use it if the add-on explicitly requires it (e.g., for hardware access). Prefer adding specific devices with devices: instead.
Can I run multiple instances of the same add-on?
Yes, by defining multiple services with different names and different volumes/ports. This is useful for separating environments, like a test and production Zigbee network.
What if an add-on is not available as a Docker image?
Some add-ons are just scripts that run on the Supervisor. In that case, you can often run them as a standalone script or find a community-maintained Docker image. Otherwise, you may need to run the add-on inside a separate container with a custom Dockerfile.