Which environment variables does the HA docker image provide for (initial) setup?

Hello,
i’m currently on my way to deploy HA on my already existing docker setup. I had already setup a simple container with it for testing purpose.
After reading a fiew forum posts i noticed that you can actually use an external mariadb & influxdb for HA. As i dont really like running individual sqlite db’s inside each container (centralized databases) i’m now trying to get HA to use my already existing mariadb & influxdb containers as database storage.

My questions now is does the HA docker image provide any environment variables for that (initial setup in docker compose) or do i always have to run the docker container itself first and then manually configure it’s configuration file? Is there a HA doc page where i can look up all the environment variables the HA image provides?

I already searched on the internet/forum/docs but i wasn’t really able to find anything useful there.

It does not support env-variables for configuration directly, but you can set variables and address them in configuration.yaml:

recorder:
  db_url: !env_var HASS_RECORDER_DB_URL
1 Like

Thats perfectly fine. I think i can work with this.

Does the configuration.yaml by any chance also support docker secrets (as i don’t want to use plain passwords in my environment variables)?

Don‘t think so, secrets are mounted at /run/secrets and that‘s beyond the scope of the HA start script.

Of course you can create a secrets.yaml and bind-mount it into the container.

1 Like

The past hour i played around with the configuration.yaml and read a little bit about homeassistant secrets, docker secrets and docker configs.

The way i did it now is:

  1. I created a docker config file which i then mounted on the HA container as my configuration.yaml (includes general settings + db_url as secret)
  2. I created a docker secret which includes my secret from the configuration.yaml which i then mounted as my secrets.yaml (you can specify a custom mount point for docker secrets in docker compose with ‘target:’)
  3. Manually created a user and a database via phpmyadmin on my mariadb container

I started the HA container and as far as i can tell it is actually using the mariadb’s database as storage. Gonna try the same with influxdb tomorrow but it looks like this will be up and running in a breeze too. Thank you very much for helping and pointing me in the right direction :slight_smile:

1 Like

I kept the docker secrets target as is, and didn’t bother to use secrets.yaml at all. Instead I modified the entrypoint to set an env variable

    secrets:
      - ha-maria-connection
    entrypoint: /bin/bash -c "export MARIA_CONNECTION=$$(cat /run/secrets/ha-maria-connection) && /init"

and consumed it in config like

recorder:
  db_url: !env_var MARIA_CONNECTION