Question: Running Homeassistant using Docker on macOS

Hello,

I am still pretty new to running Homeassistant (thanks to my good friend Keith) and I installed using Pip. However, I started getting interested in Docker because I have broken HA at least once or twice and it took a lot of work to fix the mess. I believe Docker would allow me to upgrade my environment such as Python, without fear of wrecking HA.
I found the article at http://www.phatpenguin.com/2018/12/hassio-via-docker-on-mac.html helpful; however, I have a couple of questions.
I created a yaml file I will use to fire off the Docker instance.
Here are my questions:

  1. The volume: key has - ~/hassio:/config as the value. I wanted to confirm that if - ~/hassio: is a directory in my home folder, is the /config a subdirectory? Would I put my configuration files in the /configure subdirectory?
  2. Are there any significant downsides to running Docker and Homeassistant in this manner?
  3. Any tips or things I should know?
  4. How about Appdaemon, (I know this might be a little out of scope), but any issues running it outside the container?

If there are resources I should be reading, please advise and thank you in advance.

V/r
Scott

1 Like

The local folder hassio will appear as folder config inside the container (at filesystem‘s root). On first start, HA will create /config/configuration.yaml inside the container, so you will find it as /home/hassio/configuration.yaml on the host filesystem.

No, it‘s a documented installation method called Home Assistant Container.

Learn some Docker and container basics, you‘ll need it for maintenance and debugging. And keep in mind, that containers are ephemeral. Any change inside a container will be gone, once the container is re-created (e.g. during update).

I am not familiar with this, but if AppDaemon can be contacted via filesystem or network, it will work.

1 Like

Thank you for the answers to my question. One thing that grabbed my attention is that the containers are ephemeral and are effectively replaced with an upgrade. If that is the case, I assume the best option to keep any existing configuration file is to copy an existing configuration file into the container once it is created/replaced or point to it from the one created in the container.
Although this seems like a very handy approach to getting around fighting Brew if upgrading anything, it does take some careful consideration. I guess the whole point of Docker containers is for development and throwaway environments. :slight_smile:
V/r
Scott

True for configuration.yaml, but HA creates / modifies files next to configuration.yaml (log, db, .storage directory).

But - remember the volumes: key? That volume is bi-directional and so the altered files will be kept (and persist) outside the container.

Ah, so currently I have a directory in my home folder .homeassistant and that is where all the HA files currently live. This volume key could be used to point to that folder? If my understanding is correct, it doesn’t matter what happens to the container.
This addresses the concerns I would have running Docker.

Thanks

Here is my Docker yaml file, which I haven’t actually used, just working on it.

version: ‘3’
services:
homeassistant:
container_name: home-assistant
image: homeassistant/home-assistant
volumes:
- ~/hassio:/config

If I changed the above line to point to the .homeassistant (~/.homeassistant) directory, I assume this is what you were referring to?

  - ~/hassio/etc/localtime:/etc/localtime:ro 
restart: always 
ports: 
  - "8123:8123"

THank you

Formatting got lost, but this is wrong.

volumes:
  - ~/.homeassistant:/config
  - /etc/localtime:/etc/localtime:ro 

Your local directory .homeassistant will be present at /config in the container. HA is using this for it‘s configuration and runtime data

Your global directory /etc/localtime will be present at the same location inside the container, but read-only (:ro). It‘s a standard Linux location required to handle UTC and local time

Thank you and sorry for being daft.
To clarify…
From the article I read, he created “hassio” in his home folder. He created a subfolder “/etc” where he copied the local time file.
So, following his example, there will be a /etc and /config directory in hassio. What was not clear is if you drop your configuration yaml file and other HA files into configuration. If I would merely copy the contents of .homeassistant (which I am using currently) into ~/hassio/config, perfect. The article is helpful, but does not clarify a few of these points.
I suppose if you are starting from scratch, this would all make sense. I also assume I would cause no harm in just following the instructions and seeing what the results are. :slight_smile: (stopping the currently running instance of HA) I appreciate your time answering my questions.
Lots to learn. :slight_smile:

It’s not necessary to copy /etc/localtime, as it is “mounted” read-only in the container and therefore cannot be changed from within. You can do it, but it’s a waste of time.

But yes, if you create a folder ~/hassio with subfolders etc and config then you have to adjust the volumes key

volumes:
  - ~/hassio/etc/localtime:/etc/localtime:ro
  - ~/hassio/config:/config

Ok, so no need to copy local time. From the article…

According to the article, if you want to use Docker compose (using the yaml file), you have to make a special timezone file because it does not get mapped normally on macOS.

Finally, (and last question, I promise) where will I put my HA configuration files? Would they go in the config directory?

Thanks

Ah, could be. I am not familiar with Macs.

Yes. configuration.yaml and everything next to it, incl. hidden .storage directory.

Thank you Christoph, I’ll report back after trying things out.

Scott

Christoph,

Thank you again for your help. I got everything sorted and was successful at running HA in the Docker. The nice part is, I put all the files from my existing HA installation into the Docker and it worked fine. In fact, I destroyed the Docker instance and set it up and the files were in place and recognized. The only thing I have to figure out before moving fully to the Docker is why all the switches, lights, etc. do not show up in HomeKit. They show up in HA (on the Lovelace UI menu), but not in the Home app. Suposedly if you copy all the HomeKit stuff from .storage to the new location, it should pick it up.
Of course, that didn’t work, but I’m sure I’ll figure that out soon enough. :slight_smile:
Thank you again.

1 Like

Please look at attached docker-compose.yml file.
Elemental run:

version: '3'
services:
  homeassistant:
    container_name: home-assistant
    image: ghcr.io/home-assistant/home-assistant:stable
    volumes:
      - ./ha/config:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    ports:
      - "8123:8123"

from command line run as:

docker-compose up