3

How can I specify -t and -f parameters on docker cloud build job.


- name: 'gcr.io/cloud-builders/docker'
  entrypoint: 'bash'
  args:
  - '-c'
  - |-
          docker build --network=cloudbuild -f pipeline/components/testdocker/Dockerfile  -t europe-west1-docker.pkg.dev/xxx/test .

  dir: 'mc2-AIBooster_POC/'

I get the following error: "docker build" requires exactly 1 argument"

Lucas
  • 549
  • 1
  • 4
  • 16
  • 1
    There is a different approach in the [docs](https://cloud.google.com/build/docs/building/build-containers#use-buildconfig). Can you elaborate why are you doing it this way? Try to open the dir with your `Dockerfile` and print its `pwd` and follow the docs I linked. See if it helps. – mdobrucki Mar 03 '22 at 12:27
  • I need to specify 2 commands, that`s why I do it my way. the problem is that I need to tag the image with -t and then change the DOckerfile directory with -f The error I get is "docker build" requires exactly 1 argument – Lucas Mar 03 '22 at 14:10
  • Can you provide your `cloudbuild.yaml` file? – mdobrucki Mar 03 '22 at 14:38
  • 1
    Also, have you tried adding a dot to your command? E.g. `docker build --network=cloudbuild -t europe-west1-docker.pkg.dev/image-name -f pipeline/components/testdocker . ` – mdobrucki Mar 03 '22 at 14:44

2 Answers2

2

By using -f first and then -t .

Make sure to add a dot at the end of your command

docker build --network=cloudbuild -f pipeline/components/testdocker/Dockerfile -t europe-west1-docker.pkg.dev/vf-grp-aib-dev-buildnl/docker-repository/$_PROJECT_ID/$_USER/$_BRANCH/test .
Romeo Kienzler
  • 3,373
  • 3
  • 36
  • 58
Lucas
  • 549
  • 1
  • 4
  • 16
2

You forgot to add a dot at the end of you docker build command, the order of flags shouldn't matter:

docker build --network=cloudbuild -t europe-west1-docker.pkg.dev/vf-grp-aib-dev-buildnl/docker-repository/$_PROJECT_ID/$_USER/$_BRANCH/test -f pipeline/components/testdocker/Dockerfile .

More about using docker build here.

mdobrucki
  • 462
  • 1
  • 7