Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Run Home Assistant Add-ons in Docker Compose

· 7 min read · Home Automation

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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-compose or the newer docker compose plugin).
  • 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

  1. 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/zigbee2mqtt or ~/homeassistant/esphome. This keeps configuration files organized.
  2. Write the base docker-compose.yml file. Start with a simple version that defines a service for Home Assistant Core itself. Use the official ghcr.io/home-assistant/home-assistant:stable image. 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: host
    
    Note: privileged: true and network_mode: host are 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.
  3. 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).
  4. 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: host
    
    Adjust the volume paths and device mappings to match your hardware and configuration.
  5. 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 the HASS_URL or MQTT_URL environment variables so the add-on can reach Home Assistant.
  6. 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 environment key. Always include the TZ variable to ensure correct time handling.
  7. Mount configuration files. Some add-ons expect a configuration file (like configuration.yaml for 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.
  8. Start the stack. Run docker compose up -d from the directory containing your docker-compose.yml. This pulls the images and starts the containers. Check the status with docker compose ps.
  9. 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.
  10. Set up automatic restarts and updates. Use restart: unless-stopped to ensure containers restart after a reboot or crash. To update an add-on, pull the new image with docker compose pull and then recreate the container with docker 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.sock into 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 with ports: 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-data should 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 .env file 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 config to 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 the HASS_URL to 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 the dialout group).
  • 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.