K
Q

Specify Dockerfile for gcloud build submit

October 10, 2019

I understand

gcloud
uses the Dockerfile specified in the root directory of the source (
.
) as in the command:
gcloud builds submit --tag gcr.io/[PROJECT_ID]/quickstart-image .

but I am trying to specify the Dockerfile to use to build the image which I have not found any resource on how to do that, I don't know if that is possible.

-- idrisadetunmbi
docker
kubernetes
gcloud
google-cloud-build

8 Answers

October 10, 2019

The only way to specify a Dockerfile (i.e. other than

./Dockerfile
) would be to create a
cloudbuild.yaml
per techtabu@. This config could then use the
docker
builder and provide the specific Dockerfile, i.e.:

steps:
- name: "gcr.io/cloud-builders/docker"
  args:
  - build
  - "--tag=gcr.io/$PROJECT_ID/quickstart-image"
  - "--file=./path/to/YourDockerFile"
  - .
...
images:
- "gcr.io/$PROJECT_ID/quickstart-image"

If you wish, you also get to specify an alternative name than

cloudbuild.yaml
.

The

./Dockerfile
assumption is presumably to ease the transition to Cloud Build.

I recommend you switch to using

cloudbuild.yaml
for the flexibility it provides.

-- DazWilkin
Source: StackOverflow

April 1, 2020

You can very easily do this by substituting the

.
by
./path/to/YourDockerFile
, so the
gcloud
command will be:

gcloud builds submit --tag gcr.io/[PROJECT_ID]/quickstart-image ./path/to/YourDockerFile

So you don't have to use a

cloudbuild.yaml
for this.

-- Coco
Source: StackOverflow

October 10, 2019

I am not sure if you can specify Dockerfile, but you can use

cloudbuild.yaml
file. Check gcloud documentation. If you want to rename this file, you can use
config
option.

    gcloud builds submit --config cloudbuild.yaml .

A sample

cloudbuild.yaml
file look like this,

steps:
- name: 'gcr.io/cloud-builders/docker'
  args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/quickstart-image', '.' ]
images:
- 'gcr.io/$PROJECT_ID/quickstart-image'
-- techtabu
Source: StackOverflow

September 21, 2023

I found the solution in my case was that the docker file has to be spelt with this case format Dockerfile. I had DockerFile and it won't find that. It is case sensitive.

-- Robert
Source: StackOverflow

October 13, 2021

The

gcloud
build submit will detect automatically your
Dockerfile
if present, make sure your place the file in your
root directory
. If you don't know that much about docker you can use this command

gcloud beta run deploy --source=.

Execute it at your root directory. the

buildpacks
will create the
dockerfile
for you and it is able to detect the stack of your application so it can build with its relevant tools.

-- Antoine Luckenson
Source: StackOverflow

January 21, 2021

Eventually the following hack works for me quite well. If you have e.g.

Dockerfile.prod
and
Dockerfile.dev
use the following to build the latter.

tar --exclude-vcs-ignores \  # sort-of .dockerignore support
    --transform='s|^\./Dockerfile.dev|./Dockerfile|' -zcf /tmp/togo.tgz . && \
            gcloud builds submit --tag=gcr.io/my-project/foo:latest /tmp/togo.tgz
-- Zaar Hai
Source: StackOverflow

July 27, 2023

I tried multiple solutions but they didn't work for me. I was using the bitBucket pipeline So I used the following approach.

  1. When I run stage env

    cp ./ENV/stage/Dockerfile ./Dockerfile gcloud builds submit --tag gcr.io/your-project/your-image

  2. When I run prod env

    cp ./ENV/prod/Dockerfile ./Dockerfile gcloud builds submit --tag gcr.io/your-project/your-image

-- Sheikh Juned
Source: StackOverflow

May 17, 2024

In my case, I was getting this error because the the dockerfile was all in lowercase. Just rename it to Dockerfile with an uppercase D and the command will work.

mv dockerfile Dockerfile
-- Luiz Bom
Source: StackOverflow