Fixed: HA, AppDaemon and docker-compose

I am trying to start HomeAssistant and AppDaemon from one docker-compose file.
The beauty of this, is that the containers can be linked by name. So I do not have to know the IP address HomeAssistant is running on, docker-compose will take care of this. However, this does not work for AppDaemon. I have the following docker-compose.yaml:

  version: '3'

  services:
    mosquitto:
      container_name: mosquitto
      image: eclipse-mosquitto:latest
      ports:
        - 1883:1883
      volumes:
        - /data/docker/home-assistant/mosquitto/config:/mosquitto/config
        - /data/docker/home-assistant/mosquitto/data:/mosquitto/data
        - /data/docker/home-assistant/mosquitto/log:/mosquitto/log
    homeassistant:
      container_name: home-assistant
      image: homeassistant/home-assistant:latest
      ports:
        - 8123:8123
      volumes:
        - /data/docker/home-assistant/homeassistant/config:/config
      depends_on:
        - mosquitto
    appdaemon:
      container_name: appdaemon
      image: acockburn/appdaemon:latest
      environment:
        - HA_URL="http://homeassistant:8123/"
        - HA_KEY="welcome"
      ports:
        - 5050:5050
      volumes:
        - /data/docker/home-assistant/appdaemon/config:/conf
      depends_on:
        - homeassistant

The HA_URL environment variable in the appdaemon service is not filled in correctly. There are some examples where people use a hard-coded IP address, but I do not know this address when starting docker-compose and (as a principle) would like to avoid hard-coded addresses anyway.

Does anyone have an idea how to have docker-compose use the correct HA_URL value, so AppDaemon can connect to HomeAssistant?

If I add an additional service for testing in the docker-compose.yaml

    alpine:
      container_name: alpine
      image: alpine
      command: ping homeassistant

it is pinging the homeassistant container, regardless of its IP address.

Summary

This text will be hidden

You have to explicitly specify a network for DNS resolving to work. It does not work on the default network. So just add;

networks:
- ha

To each container and specify the networks settings (if you don’t specify anything that’s ok too);

networks:
  ha:

I have almost the same docker compose file and can confirm it works. As long as you define a network.

Thnx for the quick reply. I added a ha network to all services, but AppDaemon still complains “WARNING AppDaemon: HASS: Disconnected from Home Assistant, retrying in 5 seconds”.
Adding a http password does not make a difference.

And I haven’t found a way yet to enable debug for AppDaemon in docker-compose.

Found and fixed!
For future reference, use a dedicated network and remove the trailing slash in the environment variable:

        - HA_URL="http://homeassistant:8123"   # no trailing slash!
        - HA_KEY="welcome"

Slight topic hijack, but are you running this on a pi? I wanted to throw up an appdaemon container but the default one didn’t appear to be pi compatible

No, this was for Docker on Windows (my test environment). I am running my HA on a PCengines APU2 board. Very reliable and stable hardware (but still within budget), because of the wife-acceptance-factor. :smile: I burned too many SD cards on my pi to consider is production-worthy.
I am migrating from a FreeBSD jail to Linux Docker containers now.

Nice. I’ve been looking at upgrades and keep going back and forth between a NUC. I’m about 2 years into HASS usage though and still yet to have an SD card issue…

Hi,

Sorry I know this is an old post.

I’m trying to build a docker app containing hassio and appdaemon so that the kodi input select works, however I cannot get appdaemon to communicate with hassio using your docker file.

Could you please post your most recent version?

Thanks in advance,

Ash

I now use macvlans for networking, as I want to be able to route different containers to different physical network interfaces, so your milage might vary.
Node-red is disabled as I migrated to appdaemon.
HA Dashboard is not working (still have to figure out why this does not work).

  version: '2'
  
  services:
    mosquitto:
      container_name: mosquitto
      image: eclipse-mosquitto:latest
      networks:
        dom_net:
          ipv4_address: 192.168.23.11
      volumes:
        - /etc/localtime:/etc/localtime
        - ./mosquitto/config:/mosquitto/config
        - ./mosquitto/data:/mosquitto/data
        - ./mosquitto/log:/mosquitto/log
      restart: always

    mysql:
      container_name: mysql
      image: mysql/mysql-server:5.7
      environment:
        MYSQL_RANDOM_ROOT_PASSWORD: "yes"
        MYSQL_USER: <user here>
        MYSQL_PASSWORD: <password here>
        MYSQL_DATABASE: <database here>
      networks:
        dom_net:
          ipv4_address: 192.168.23.12
      volumes:
        - /etc/localtime:/etc/localtime
        - ./mysql/data:/var/lib/mysql
      restart: always

    nginx:
      container_name: nginx
      image: nginx:latest
      networks:
        dom_net:
          ipv4_address: 192.168.23.13
      volumes:
        - /etc/localtime:/etc/localtime
        - ./nginx/config:/etc/nginx/conf.d
        - ./nginx/data:/var/www
        - ./nginx/log:/var/log/nginx
      restart: always

    homeassistant:
      container_name: homeassistant
      image: homeassistant/home-assistant:latest
      networks:
        dom_net:
          ipv4_address: 192.168.23.14
      volumes:
        - /etc/localtime:/etc/localtime
        - ./homeassistant/config:/config
      depends_on:
        - mosquitto
        - mysql
      restart: always
      
    appdaemon:
      container_name: appdaemon
      image: acockburn/appdaemon:latest
      environment:
        HA_URL: "http://homeassistant:8123"
        HA_KEY: <your ha key here>
        DASH_URL: "http://appdaemon:5050"
      networks:
        dom_net:
          ipv4_address: 192.168.23.15
      volumes:
        - /etc/localtime:/etc/localtime
        - ./appdaemon/config:/conf
      depends_on:
        - homeassistant
      restart: always
        
#   nodered:
#     container_name: nodered
#     image: nodered/node-red-docker:v8
#     networks:
#       dom_net:
#         ipv4_address: 192.168.23.16
#     volumes:
#       - /etc/localtime:/etc/localtime
#       - ./nodered/config:/data
#     depends_on:
#       - mosquitto
#     restart: unless-stopped

  networks:
    dom_net:
      driver: macvlan
      driver_opts:
        parent: enp3s0
      ipam:
        config:
          - subnet: 192.168.23.0/24
            gateway: 192.168.23.254

Great thank you