google-cloud-platformgcloudgoogle-cloud-run

How to use gcloud run deploy to specify a particular Dockerfile?


I have a directory that contains multiple Dockerfiles, such as api.Dockerfile and ui.Dockerfile. When using gcloud run deploy, I want to specify which Dockerfile should be used for building the container. Specifically, I want gcloud run deploy to take only api.Dockerfile.

Here’s the directory structure:

/project-directory
  ├── api.Dockerfile
  ├── ui.Dockerfile
  ├── src/
  └── other-files/

Is there an option with gcloud run deploy to specify a particular Dockerfile (e.g., api.Dockerfile) instead of the default Dockerfile?


Solution

  • No, gcloud run deploy doesn't have an option to directly specify the docker image file name. But you can achieve this using a two-step process:

    1. Build the docker image using the docker build command, pass the dockerfile location and assign a name to the image.
    2. Use the gcloud run deploy command with the --container option, specifying the name you assigned to the image in step 1.

    Here's an example:

    docker build -t myimage -f api.Dockerfile .
    
    gcloud run deploy --container=myimage