{"id":51188,"date":"2020-05-28T17:37:10","date_gmt":"2020-05-28T07:37:10","guid":{"rendered":"http:\/\/riscy.biz\/?p=51188"},"modified":"2020-05-28T17:37:10","modified_gmt":"2020-05-28T07:37:10","slug":"home-assistant-in-a-docker-container","status":"publish","type":"post","link":"https:\/\/riscy.biz\/index.php\/2020\/05\/28\/home-assistant-in-a-docker-container\/","title":{"rendered":"Home Assistant in a Docker container"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I&#8217;ve managed to move my current Home Assistant install from a python virtual environment to Docker. This will allow me to upgrade the host operating system or move to a new computer without too much difficulty. The most difficult thing to get working was the networking and it took me a while to work out which containers needed to be on the host network and which could be on the default docker network.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">My Docker stack has the following components:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Mosquitto<\/li><li>Zigbee2MQTT<\/li><li>Home Assistant<\/li><li>NodeRed<\/li><li>ESPhome<\/li><li>Lets-encrypt<\/li><li>My own personal power monitor Perl script<\/li><li>Watchtower<\/li><li>MySQL<\/li><li>phpMyAdmin<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Eventually I&#8217;ll move my Plex install into the same environment but I&#8217;m waiting for me new 8Tb hard drive.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The docker-compose file looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>version: '3.5'\nservices:\n  mosquitto:\n    container_name: mqtt\n    hostname: mqtt\n    image: eclipse-mosquitto\n    labels:\n      - com.centurylinklabs.watchtower.enable=true\n    restart: always\n    ports:\n      - 1883:1883\n      - 8883:8883\n      - 9001:9001\n    volumes:\n      - \/mnt\/data\/docker\/mosquitto\/config:\/mosquitto\/config\n      - \/mnt\/data\/docker\/mosquitto\/data:\/mosquitto\/data\n      - \/mnt\/data\/docker\/mosquitto\/log:\/mosquitto\/log\n      - \/etc\/localtime:\/etc\/localtime:ro\n\n  zigbee2mqtt:\n    container_name: zigbee2mqtt\n    hostname: zigbee2mqtt\n    image: koenkk\/zigbee2mqtt:latest\n    volumes:\n      - \/mnt\/data\/docker\/zigbee2mqtt:\/app\/data\n      - \/run\/udev:\/run\/udev:ro\n      - \/etc\/localtime:\/etc\/localtime:ro\n    devices:\n      - \/dev\/ttyACM0:\/dev\/ttyACM0\n    depends_on:\n      - mosquitto\n    restart: always\n    privileged: true\n    environment:\n      - TZ=Australia\/Hobart\n\n  homeassistant:\n    container_name: homeassistant\n    hostname: homeassistant\n    image: homeassistant\/home-assistant\n    volumes:\n      - \/mnt\/data\/docker\/homeassistant:\/config\n      - \/etc\/localtime:\/etc\/localtime:ro\n    depends_on:\n      - mosquitto\n    restart: always\n    network_mode: host\n\n  nodered:\n    container_name: nodered\n    hostname: nodered\n    labels:\n      - com.centurylinklabs.watchtower.enable=true\n    network_mode: host\n    image: nodered\/node-red-docker:latest\n    ports:\n      - 1880:1880\n    volumes:\n      - \/mnt\/data\/docker\/node-red:\/data\n      - \/etc\/localtime:\/etc\/localtime:ro\n    depends_on:\n      - mosquitto\n      - homeassistant\n    restart: always\n    environment:\n      - TZ=Australia\/Hobart\n\n  esphome:\n    container_name: esphome\n    hostname: esphome\n    image: esphome\/esphome\n    labels:\n      - com.centurylinklabs.watchtower.enable=true\n    volumes:\n      - \/mnt\/data\/docker\/esphome:\/config\n      - \/etc\/localtime:\/etc\/localtime:ro\n    restart: always\n    network_mode: host\n    \n  lets-encrypt:\n    container_name: letsencrypt\n    hostname: letsencrypt\n    image: linuxserver\/letsencrypt\n    labels:\n      - com.centurylinklabs.watchtower.enable=true\n    restart: always\n    volumes: \n      - \/mnt\/data\/docker\/homeassistant\/letsencrypt:\/config\n      - \/etc\/localtime:\/etc\/localtime:ro\n    ports:\n      - 433:433\n    cap_add:\n      - NET_ADMIN\n    environment:\n      - PUID=1000\n      - PGID=1000\n      - EMAIL=chris.jennings@riscy.biz\n      - URL=#####\n      - VALIDATION=duckdns\n      - TZ=Australia\/Hobart\n      - DUCKDNSTOKEN=#######\n\n  powerlog:\n    container_name: powerlog\n    hostname: powerlog\n    image: powerlog\n    restart: always\n    privileged: true\n    volumes:\n      - \/mnt\/data\/docker\/powerlog:\/usr\/src\/myapp\n      - \/run\/udev:\/run\/udev:ro\n      - \/etc\/localtime:\/etc\/localtime:ro\n    devices:\n      - \/dev\/ttyUSB0:\/dev\/ttyUSB0\n    links:\n      - mysql:mysql\n    command: perl \/usr\/src\/myapp\/powerlog.pl      \n\n  watchtower:\n    container_name: watchtower\n    image: containrrr\/watchtower\n    command: --cleanup --label-enable\n    restart: always\n    volumes:\n      - \/var\/run\/docker.sock:\/var\/run\/docker.sock\n      - \/etc\/timezone:\/etc\/timezone:ro\n      - \/etc\/localtime:\/etc\/localtime:ro\n  mysql:\n    container_name: mysql\n    hostname: mysql\n    image: mysql\n    ports:\n      - 3306:3306\n    restart: always\n    volumes:\n      - \/mnt\/data\/docker\/mysql:\/var\/lib\/mysql\n      - \/etc\/localtime:\/etc\/localtime:ro\n\n  phpmyadmin:\n    container_name: phpmyadmin\n    hostname: phpmyadmin\n    image: phpmyadmin\/phpmyadmin\n    ports:\n      - 8080:80\n    restart: always\n    volumes:\n      - \/mnt\/data\/docker\/phpmyadmin:\/sessions\n      - \/etc\/localtime:\/etc\/localtime:ro\n    links:\n      - mysql:db<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I have all the docker mounted volumes in a folder \/mnt\/data\/docker. To migrate MySQL I had to export the data and then import it into the new docker container. Copying the files over didn&#8217;t work, maybe it was because the MySQL version was incompatible. Best practice usually requires a mysqldump and import instead of just copying the MySQL files over.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ensure that host names are set correctly so that containers can talk to each other. I also mounted \/etc\/localtime on each container to ensure the time is correct. Initially my Perl script was time stamping incorrectly because I didn&#8217;t map the time through.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve managed to move my current Home Assistant install from a python virtual environment to Docker. This will allow me to upgrade the host operating system or move to a new computer without too much difficulty. The most difficult thing &hellip; <a href=\"https:\/\/riscy.biz\/index.php\/2020\/05\/28\/home-assistant-in-a-docker-container\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-51188","post","type-post","status-publish","format-standard","hentry","category-computers"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/riscy.biz\/index.php\/wp-json\/wp\/v2\/posts\/51188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/riscy.biz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/riscy.biz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/riscy.biz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/riscy.biz\/index.php\/wp-json\/wp\/v2\/comments?post=51188"}],"version-history":[{"count":0,"href":"https:\/\/riscy.biz\/index.php\/wp-json\/wp\/v2\/posts\/51188\/revisions"}],"wp:attachment":[{"href":"https:\/\/riscy.biz\/index.php\/wp-json\/wp\/v2\/media?parent=51188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/riscy.biz\/index.php\/wp-json\/wp\/v2\/categories?post=51188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/riscy.biz\/index.php\/wp-json\/wp\/v2\/tags?post=51188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}