0

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 :)

wallismark
  • 1,766
  • 2
  • 21
  • 35

2 Answers2

0

If the image is defined like this into you docker compose file:

image: ${DOCKER_REGISTRY-}sample-blazorapp

then you must export using a slash at the end of the value:

export DOCKER_REGISTRY="myregistry/"
  • Thank you for answering, although you are probably correct that I need to add the trailing slash, the main problem is the environment variable is not being picked up in the context of the docker-compose file at all. It's just reading {DOCKER_REGISTRY} as is, as a string. – wallismark Aug 05 '22 at 03:28
0

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
wallismark
  • 1,766
  • 2
  • 21
  • 35