2

I have a docker compose file that builds and runs a couple of dockerfiles locally. I am using multi-stage builds and I pass an argument into my docker build commands. The following works perfectly:

docker build -t local/admin-api --build-arg SONAR_TOKEN=XXXXXXXXXXXXXXX .

I am trying to replicate that in my docker compose file with:

services:
  comply:
    build:
      context: ./websites/comply/
      dockerfile: Dockerfile
      args:
        SONAR_TOKEN: xxxxxxxxxxx
    ports:
      - "8080:80"

In my dockerfile I use:

FROM kinectify.azurecr.io/buildbase:ci-631 as build

ARG PAT
ARG SONAR_PROJECT_KEY=xxxxxxx
ARG SONAR_ORGANIZATION_KEY=xxxxxxx
ARG SONAR_HOST_URL=https://sonarcloud.io
ARG SONAR_TOKEN

RUN echo "Token: ${SONAR_TOKEN} | hostURL: ${SONAR_HOST_URL}"

I am aware of the scoping of build args, and as you can see above, the arg is defined after my FROM statement. I have also tried setting the arg to an environment variable, but that doesn't seem to matter. Additionally, the SONAR_HOST_URL is being output correctly in echo statement (and in the place where I am actually using the argument). I am running the build with:

docker compose build comply

** UPDATE **

Strangely, when I run docker compose up -d --build it does pass variable. I am not sure what the difference is though.

1
  • Your update save my life, thank you Commented Sep 27, 2023 at 2:37

1 Answer 1

4

This is a known issue that's been fixed in docker compose. You are likely waiting for the next release still. Using docker-compose instead of docker compose should also work while you wait for that release.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.