{"id":1979,"date":"2018-01-15T08:52:00","date_gmt":"2018-01-15T07:52:00","guid":{"rendered":"https:\/\/akim.sissaoui.com\/en\/?p=1979"},"modified":"2018-01-15T15:57:24","modified_gmt":"2018-01-15T14:57:24","slug":"hass-updating-home-assistant-docker-image","status":"publish","type":"post","link":"https:\/\/akim.sissaoui.com\/en\/informatique\/hass-updating-home-assistant-docker-image\/","title":{"rendered":"HASS: Deploy and update Home Assistant from Docker Hub"},"content":{"rendered":"<h1>Home Assistant deployment and update from Docker Hub<\/h1>\n<h2>Introduction<\/h2>\n<p><a href=\"https:\/\/akim.sissaoui.com\/wp-content\/uploads\/2018\/01\/docker2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-1983\" src=\"https:\/\/akim.sissaoui.com\/wp-content\/uploads\/2018\/01\/docker2-300x268.png\" alt=\"\" width=\"186\" height=\"166\" srcset=\"https:\/\/akim.sissaoui.com\/wp-content\/uploads\/2018\/01\/docker2-300x268.png 300w, https:\/\/akim.sissaoui.com\/wp-content\/uploads\/2018\/01\/docker2-768x685.png 768w, https:\/\/akim.sissaoui.com\/wp-content\/uploads\/2018\/01\/docker2-1024x914.png 1024w, https:\/\/akim.sissaoui.com\/wp-content\/uploads\/2018\/01\/docker2-108x96.png 108w, https:\/\/akim.sissaoui.com\/wp-content\/uploads\/2018\/01\/docker2.png 1354w\" sizes=\"(max-width: 186px) 100vw, 186px\" \/><\/a>I&#8217;ve been using Home Assistant for about one month now. And to make it simple, I deployed it inside a Docker Container out of Docker Hub. This is quite new for me. It&#8217;s my first use of Docker. And I like it. It makes things a lot simple.<!--more--><\/p>\n<p>If you want to try Home Assistant in a Docker Container, you can find <a href=\"https:\/\/home-assistant.io\/docs\/installation\/docker\/\" target=\"_blank\" rel=\"noopener\">installation instructions<\/a> on the Home Assistant web site to do so. It&#8217;s quite straight forward once Docker has been installed. The most important part is about the volume, to ensure your dynamic data is stored on your own file system, and not into the container file system.<\/p>\n<p>Consider the container like you would consider an Ikea mounting diagram. It gives instruction, but you don&#8217;t through away your furniture with it when you&#8217;re done, right ? If you do not do the volume part, all your data, which makes your application useful, will be stored within the container&#8230; and be deleted when you stop the container.<\/p>\n<p>Once you grab the way it works, it&#8217;s easy to understand how updating a container can be simple. When a new version is released, you just get rid of the existing image, and download the new one, delete your container and make a new one.<\/p>\n<h2>Deploy and operate Home Assistant from Docker Hub<\/h2>\n<h3>Deploy Home Assistant docker container<\/h3>\n<p>So, once docker is installed, to run Home Assistant from docker hub, just launch following command. In this example, I have 1st created a \/home\/autoadmin\/hass folder which will be mounted into the container as \/config. That&#8217;s where Home Assistant keep data. I also added &#8211;restart unless-stopped. Self explanatory. This allows my container to restart if the server restarts for whatever reason.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">docker run -d --restart unless-stopped --name=\"hass\" -v \/home\/autoadmin\/hass:\/config -v \/etc\/localtime:\/etc\/localtime:ro --net=host homeassistant\/home-assistant<\/pre>\n<h3>Access the container log<\/h3>\n<p>To check the log, you can use the following command. The &#8211;since parameter allow to see only the last entries. It can be m for minutes, s for seconds or h for hours. In this example, I use &#8211;since 1m so I can see what happened in the last 1 minute. And -f is equivalent to tail -f allowing me to monitor the what is happening into the docker container in real time.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">docker logs hass --since 5m -f<\/pre>\n<p>If you want to grep the log, you cannot directly from the docker logs command. So you can use this as an alternative:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">docker logs hass --since 2m |  2>\/dev\/null | grep keyword<\/pre>\n<h3>Limiting the container log<\/h3>\n<p>Still, going through the docker log can be cumbersome as it is stored in a JSON file, and even with the &#8211;since parameter, it still sequentially parses the complete file to show you the last minutes&#8230; So you don&#8217;t seen what you don&#8217;t need, but you still wait until it is processed ! So, until I find a tool which can parse JSON logs from dockers and provide me an easier way to monitor, I looked for a way to limit the log size.<\/p>\n<p>Depending on a lot of parameter, I guess the log size can from from less than 1MB a day if you only log warnings, to 10, perhaps 20MB a day if you debug, what I&#8217;ve been doing recently. I&#8217;ve decided for now to limit the log size to 10MB. This can be done with &#8211;log-opt parameter:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">docker run -d --restart unless-stopped --name=\"hass\" --log-opt max-size=10m -v \/home\/autoadmin\/hass:\/config -v \/etc\/localtime:\/etc\/localtime:ro --net=host homeassistant\/home-assistant<\/pre>\n<h2>Upgrading Home Assistant from Docker Hub<\/h2>\n<p>Today, when accessing my Home Assistant front-end, I got a notification that version 0.60.1 has been released. I&#8217;m currently running version 0.60.0. If you follow t<a href=\"https:\/\/home-assistant.io\/docs\/installation\/docker\/\" target=\"_blank\" rel=\"noopener\">he installation instructions from the Home Assistant website<\/a>, starting Home Assistant from a Docker container is straight forward. However, when it come to updates, it&#8217;s not that obvious if you never did it before. The Update documentation does not cover Docker update. Well, might be because it&#8217;s pretty simple, but like Columbo&#8217;s eggs, nothing&#8217;s obvious until it has been shown.<\/p>\n<p>When a new version is released, you can pull the new image. This will download the container containing the new version. You have then to stop and remove your existing container and run a new one based on the new image. Interestingly, you can make a copy of your data 1st, and run another container with the new version on a different port before to upgrade, to ensure all is working as expected. I might do an article about that later,but not now&#8230;.<\/p>\n<p>So, 1st, we pull the latest image:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">docker pull homeassistant\/home-assistant<\/pre>\n<p>This will download the new image from docker hub. To upgrade, 1st of all, make a copy of your data in a safe place (you should anyway backup your data before any change, additionally to your usual backup). The, stop your current container, delete it, and run a new container. It will automatically take the new image, considering you did not pull a different image obviously:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\"># Stop existing container\r\ndocker stop hass\r\n\r\n# Delete existing container\r\ndocker rm hass\r\n\r\n# Run new container\r\ndocker&nbsp;run&nbsp;-d&nbsp;--restart&nbsp;unless-stopped&nbsp;--name=\"hass\"&nbsp;--log-opt&nbsp;max-size=10m&nbsp;-v&nbsp;\/home\/autoadmin\/hass:\/config&nbsp;-v&nbsp;\/etc\/localtime:\/etc\/localtime:ro&nbsp;--net=host&nbsp;homeassistant\/home-assistant\r\n<\/pre>\n<p>You&#8217;re done. You can monitor the log for startup progression.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">docker logs hass --since 1m -f<\/pre>\n<p>You can now delete the old image which is not required anymore. List existing images<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">docker images\r\n<\/pre>\n<p>You&#8217;ll see the list of images on your server. You will see two homeassistant\/home-assistant images, with two image IDs, and only one will be tagged as latest. You can delete the other one<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE\r\nhomeassistant\/home-assistant   latest              04d0d1debd6a        9 days ago          1.65GB\r\nhomeassistant\/home-assistant   (none)              4f76b7e73b00        4 weeks ago         1.65GB<\/pre>\n<p>Delete the useless image<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">docker rmi 4f76b7e73b00<\/pre>\n<p>That will save you some space \ud83d\ude42<\/p>\n<p>You&#8217;re done. Just go to your Home assistant web interface, check in Configuration, and you&#8217;ll see the new version.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Home Assistant deployment and update from Docker Hub Introduction I&#8217;ve been using Home Assistant for about one month now. And to make it simple, I deployed it inside a Docker Container out of Docker Hub. This is quite new for me. It&#8217;s my first use of Docker. And I like it. It makes things a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[220],"tags":[265,266],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/posts\/1979"}],"collection":[{"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/comments?post=1979"}],"version-history":[{"count":7,"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/posts\/1979\/revisions"}],"predecessor-version":[{"id":1987,"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/posts\/1979\/revisions\/1987"}],"wp:attachment":[{"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/media?parent=1979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/categories?post=1979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/tags?post=1979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}