Search code examples
bamboo

Variable Substitution with Bamboo in Dockerfile


My Dockerfile looks like the following:

from httpd:${bamboo.test.tag}
COPY index.html /usr/local/apache2/htdocs/

In Bamboo I have a task with the following script:

docker build --no-cache -t myproj/my .

When running the job, I get the following error:

build   26-Sep-2022 10:42:26    Step 1/2 : from httpd:${bamboo.test.tag}
error   26-Sep-2022 10:42:26    failed to process "httpd:${bamboo.test.tag}": missing ':' in substitution

How can I substitute the tag?


Solution

  • This is actually a problem with how you are using the dockerfile.

    Docker will not expand environment variables inside your Dockerfile. You need to pass the environment value as a build argument in the docker build command then use the ARG keyword inside the Dockerfile.

    Your Dockerfile would look like this:

    ARG IMAGE_TAG
    from httpd:${IMAGE_TAG}
    COPY index.html /usr/local/apache2/htdocs/
    

    And you would need to change you docker build command to:

    docker build --no-cache --build-arg IMAGE_TAG=${bamboo.test.tag} -t myproj/my .
    

    Check a more detailed explanation here