Skip to content

La vie rêvée d’Akim

…ou le zèbre qui voulait être un homme

  • Style de vie
  • Informatique
  • Photographie
  • Musique
  • English (US)English (US)
  • FrançaisFrançais

HASS: Deploy and update Home Assistant from Docker Hub

Posted on Monday 15 January 2018 - Monday 15 January 2018 by Akim

Home Assistant deployment and update from Docker Hub

Introduction

I’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’s my first use of Docker. And I like it. It makes things a lot simple.

If you want to try Home Assistant in a Docker Container, you can find installation instructions on the Home Assistant web site to do so. It’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.

Consider the container like you would consider an Ikea mounting diagram. It gives instruction, but you don’t through away your furniture with it when you’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… and be deleted when you stop the container.

Once you grab the way it works, it’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.

Deploy and operate Home Assistant from Docker Hub

Deploy Home Assistant docker container

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’s where Home Assistant keep data. I also added –restart unless-stopped. Self explanatory. This allows my container to restart if the server restarts for whatever reason.

docker run -d --restart unless-stopped --name="hass" -v /home/autoadmin/hass:/config -v /etc/localtime:/etc/localtime:ro --net=host homeassistant/home-assistant

Access the container log

To check the log, you can use the following command. The –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 –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.

docker logs hass --since 5m -f

If you want to grep the log, you cannot directly from the docker logs command. So you can use this as an alternative:

docker logs hass --since 2m |  2>/dev/null | grep keyword

Limiting the container log

Still, going through the docker log can be cumbersome as it is stored in a JSON file, and even with the –since parameter, it still sequentially parses the complete file to show you the last minutes… So you don’t seen what you don’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.

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’ve been doing recently. I’ve decided for now to limit the log size to 10MB. This can be done with –log-opt parameter:

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

Upgrading Home Assistant from Docker Hub

Today, when accessing my Home Assistant front-end, I got a notification that version 0.60.1 has been released. I’m currently running version 0.60.0. If you follow the installation instructions from the Home Assistant website, starting Home Assistant from a Docker container is straight forward. However, when it come to updates, it’s not that obvious if you never did it before. The Update documentation does not cover Docker update. Well, might be because it’s pretty simple, but like Columbo’s eggs, nothing’s obvious until it has been shown.

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….

So, 1st, we pull the latest image:

docker pull homeassistant/home-assistant

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:

# Stop existing container
docker stop hass

# Delete existing container
docker rm hass

# Run new container
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

You’re done. You can monitor the log for startup progression.

docker logs hass --since 1m -f

You can now delete the old image which is not required anymore. List existing images

docker images

You’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

REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
homeassistant/home-assistant   latest              04d0d1debd6a        9 days ago          1.65GB
homeassistant/home-assistant   (none)              4f76b7e73b00        4 weeks ago         1.65GB

Delete the useless image

docker rmi 4f76b7e73b00

That will save you some space 🙂

You’re done. Just go to your Home assistant web interface, check in Configuration, and you’ll see the new version.

 

Posted in InformatiqueTagged docker, home assistant

Post navigation

Script: Create a github repository, a git local directory, and link them in a single script
WordPress plugins and headache

5 Comments

  1. Pivert says:
    Sunday 3 June 2018 at 23:41

    Hello Akim,

    Comment peut-on accéder à l’interface web de hass puisque tu ne rediriges aucun port ?

    Merci,

  2. Akim says:
    Friday 14 September 2018 at 18:39

    Désolé je n’avais pas vu ton comm. Je n’accède pas HASS depuis l’extérieur je n’ai donc pas besoin de redirection.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Proudly powered by WordPress | Theme: micro, developed by DevriX.