Setting up the development environment

I started off by running HA from a docker-compose file as instructed on the official documentation. This of course worked fine but I quickly got into trouble with HA’s /config directory.

The /config directory stores YAML configuration files and the main database so we need to tell docker to treat it as persistent data. Official docs suggest the use of bind mounting to achieve this. Unfortunately, bind mounts are not allowed on balena so I had to work around that with this setup:

This are the modifications that I made:

Change /config directory mount type from bind mount to named volume. Create a docker image based on the official one that copies the /config directory from our project folder into the container. Bind mount the named volume back to the project folder.

It looks like we’ve done a lot of work for nothing since we are still using a bind mount but there is a reason for that. Let me explain…

Since we are now using a named volume we need to include our custom configuration files on the docker image. This means we need to rebuild our image every time a config file changes. For our development environment this is far from ideal since we will be modifying those files often. This is why we need modification #3 but only for development.

With all this in mind, here is what our development docker-compose.yml file looks like:

And the Dockerfile: