Search code examples
docker-composeazure-container-apps

how to set an environment variable when run - az container app compose create


It seems when my docker compose yml is run via "az containerapp compose create", environment variables are not picked up. Is there a way I can set an env variable so the command picks it up?

I'm seeing this error:

ERROR: The following field(s) are either invalid or missing. Invalid value: "${DOCKER_REGISTRY-}/sample-blazorapp": could not parse reference: ${DOCKER_REGISTRY-}/sample-blazorapp: template.containers.blazorapp.image.

I have set the variable with: export DOCKER_REGISTRY="myregistry"

And when I echo $DOCKER_REGISTRY, the value is returned. So in the bash session it is set (I tried powershell first, I thought that was the issue because $(envvar-) is bash syntax, however the error is the same.)

This is what I have in my compose file (alignment is correct in the file):

blazorapp:
container_name: "blazorapp"
image: ${DOCKER_REGISTRY-}sample-blazorapp
build:
  context: .
  dockerfile: BlazorApp/BlazorApp/Dockerfile
depends_on:
  - redis
ports:
  - "55000:443"

If I explicitly set the image name, i.e. not use an env var, then it works. i.e. this change to the image line works:

image: myregistry/sample-blazorapp

I also tried adding the forward slash, this makes no difference (as expected, it works fine without the slash when running docker compose up).

I can set it explicitly but that would be annoying. I feel like I'm missing something. Any help or guidance is greatly appreciated :)


Solution

  • I discovered the issue, I was missing a colon.

    Does not work (produces the error described in the question):

    image: ${DOCKER_REGISTRY-}sample-blazorapp
    

    Also does not work:

    image: ${DOCKER_REGISTRY-mydefault}sample-blazorapp
    

    Add the magic : in and it works:

    image: ${DOCKER_REGISTRY:-}sample-blazorapp
    

    Also works:

    image: ${DOCKER_REGISTRY:-mydefault}sample-blazorapp