Search code examples
dockergoogle-cloud-platformgoogle-cloud-build

Google Cloud Build Docker build-arg not respected


I'm having a problem with Google Cloud Build where the docker build command doesn't seem to be accepting the build-arg option, even though this same command works as expected on local:

Dockerfile:

ARG ASSETS_ENV=development
RUN echo "ASSETS_ENV is ${ASSETS_ENV}"

Build Command:

docker build --build-arg="ASSETS_ENV=production" .

Result on local:

ASSETS_ENV is production

Result on Cloud Build:

ASSETS_ENV is development

Solution

  • Ok the fix was in the cloud build yaml config:

    Before:

    - name: 'gcr.io/cloud-builders/docker'
      args: ['build', '--build-arg="ASSETS_ENV=production"', '.']
    

    After:

    - name: 'gcr.io/cloud-builders/docker'
      entrypoint: 'bash'
      args: ['-c', 'docker build --build-arg="ASSETS_ENV=production" .']