Search code examples
dockerdockerfilegithub-actionsdocker-build

Docker --build-arg defined but not mandatory


I'm building my docker image in a generic way so that might be used by multiple services, however not all the --build-arg will be present because it depends on the service that is being called on the GitHub Actions. My question is; is it possible to use only one or more --build-arg without using every --build-arg?

Command:

docker build \
  -f ${{ inputs.docker-location }} \
  -t $IMAGE_NAME:$TAG \
  --build-arg value1=${{secrets.value1}} \
  --build-arg value2=${{ secrets.value2}} \
  --build-arg value3=${{secrets.value3}} \
  --build-arg value4=${{ secrets.value4 }} . 

So in this case I would only pass the value1 and value2, however, it fails because the rest of the values will be empty.

I know it works if all args are present, as I'm already using it, but wanted to expand it in a more generic way.

Thanks in advance! :)


Solution

  • is it possible to use only 1 or more --build -arg without using every --build-arg?

    Yes, you can do this by defining a default ARG in the Dockerfile, e.g:

    ARG value4=FOO
    

    For more information: https://docs.docker.com/engine/reference/builder/#default-values