Docker-compose: environment variables?

Hi everybody,

I tried searching the forums, but didn’t find what I need (and must have missed it in the docs as well).

Is it possible to set environment variables when using docker-compose to run Home Assistant? My docker-compose.yaml looks like this

---
version: "3.3"
services:
  hass:
    container_name: hass
    image: homeassistant/home-assistant:latest
    volumes:
      - ./data:/config
      - /etc/localtime:/etc/localtime:ro
    environment:
      - TZ=Europe/Berlin
    restart: always
    network_mode: host

Example use case: I need the myfitnesspal pip package. I can manually add it by docker exec -it hass pip install myfitnesspal on the machine Home Assistant runs on, but this needs to be repeated every single time the docker container gets an update.

One could also modify the Dockerfile and build a custom Home Assistant image, but I would prefer always updating by using the official image.

I found this example on github, where the user sets a ton of environment values… but some of those (for example, HA_HANNES_WORK_LATITUDE) look arbitrary to me.

Are the official environment values one can set in their docker-compose.yaml to define things such as pip packages to be installed (besides those that are installed anyway, of course)? And if so, where can I find a complete list of what’s possible to integrate?

Thank you for your input :slight_smile:

You’re already setting the TZ environment variable based on what you posted here.
If you need to set more, just add more lines after that line following the same format.

Right. But TZ is in all my docker-compose.yamls "just because"™. I don’t know if it is even specific to (or valid for) Home Assistant.

Let’s say I want additional pip packages to be installed. What environment variable (if any) do I set so that Home Assistant will install these for me?

You would need to rebuild the image in order to add pip packages. Environment variables wont help much unless the entrypoint in the docker container is setup to read one and install them.

That being said, your title for this thread feels less than appropriate, given this is not about env variables, but rather about modifying a docker image.

FWIW, this would be a simple change, since you are taking the official docker image and just adding some pip packages.