Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

docker: Error response from daemon: invalid mount config for type "bind"

Hi, 

    Need help in resolving the following  error in theCloudBuild run with following content in  cloudbuild.yaml file,:

steps:
  - name: gcr.io/cloud-builders/docker
     entrypoint: bash
     args:
     - -c
     - | 
       docker run --rm --mount type=bind,source=$(PWD),target=/scan registry.fortidevsec.forticloud.com/fdevsec_sast:latest

 

docker: Error response from daemon: invalid mount config for type "bind": field Source must not be empty.
See 'docker run --help'.
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 125
 
Basic Idea, is to run the following command, in the Cloud Build step in the CI/CD Pipeline:
docker run --rm --mount type=bind,source=$(PWD),target=/scan registry.fortidevsec.forticloud.com/fdevsec_sast:latest
1 1 3,039
1 REPLY 1

Here, the main differences between $(pwd) and $PWD have been discussed, where the first one that uses the parentheses is only a variable that ends up replacing it with the built-in $PWD variable from the shell. At the end, both variables can fail if they are not properly set up or if the shell you are using to deploy these files does support the $() syntax. 

It was tested without the parentheses and it worked fine. However, you should check how it works on your side and if you have the correct working directory when deploying.

As an extra comment, I would like to say that even if PWD is not a substitution, you need to follow certain guidelines described here, and these do not include the parentheses either, instead try using curly brackets {} (or not using them also works) and an _underscore at the beginning.