Help with Expanding Environment Variables in Dockerfile.template from docker-compose.yml

Hello,
I’m currently working on a project where I need to pass environment variables (PIP_USERNAME and PIP_PASSWORD) from a docker-compose.yml file to a Dockerfile.template for a build process on a Raspberry Pi 3. My setup involves using direnv to load environment variables.

Here’s a snippet of my docker-compose.yml:

test_template:
build:
context: ./test_build
args:
BRANCH_NAME: devel
PIP_USERNAME: ${PIP_USERNAME}
PIP_PASSWORD: ${PIP_PASSWORD}
restart: always

And my Dockerfile.template looks like this:

FROM balenalib/raspberrypi3-debian-python:3.9-bullseye-run
ARG PIP_USERNAME=‘’
ARG PIP_PASSWORD=‘’
WORKDIR /usr/src/app
COPY ./mis_modulos_python.txt .
RUN pip install -r mis_modulos_python.txt

I’m encountering an issue where the PIP_USERNAME and PIP_PASSWORD variables do not seem to be expanding with their respective values when passed to the Dockerfile.template. I’m using direnv for managing environment variables.

Could anyone guide me on how to correctly pass and expand these build arguments from the docker-compose.yml to the Dockerfile.template? Any suggestions or examples would be greatly appreciated!

Thank you in advance for your help!

Matias
@mpous