Deploy a Docker image to Google Cloud using Cloud Run

In this article, I would like to document how I deploy a Docker image to Google Cloud using Cloud Run.

Table of Contents

Build the docker image
Configure Google Cloud
Deploy to Google Cloud

Build the docker image

Refer to my…


This content originally appeared on DEV Community and was authored by Ada Cheng

In this article, I would like to document how I deploy a Docker image to Google Cloud using Cloud Run.

Table of Contents

  • Build the docker image
  • Configure Google Cloud
  • Deploy to Google Cloud

Build the docker image

Refer to my article Dockerizing a Node.js web application for developing a Node.js application and building a docker image.

Configure Google Cloud

Create a Google Cloud Project

If you have already created a project, you can skip this section and go directly to Configure a Google Cloud Project.

  1. In Google Cloud Shell, perform the following steps:

    1. Lists credentialed accounts and make sure the desired account is set active.

      gcloud auth list
      
    2. Create a project.

      gcloud projects create PROJECT_ID
      
    * *Replace PROJECT_ID with your desired project ID.*
    
  2. Enable Billing in Google Cloud Console.

Configure a Google Cloud Project

  1. List all projects.

    gcloud projects list
    
  2. Set the default project.

    gcloud config set project PROJECT_ID
    
* *Replace PROJECT_ID with your project ID.*
  1. Print the project ID.

    echo $GOOGLE_CLOUD_PROJECT
    
  2. Set the default zone if it is not set:

    gcloud config set compute/zone COMPUTE_ZONE
    
* *Replace COMPUTE_ZONE with your compute zone, such as europe-west2-c.*
  1. Set the default region if it is not set:

    gcloud config set compute/region COMPUTE_REGION
    
* *Replace COMPUTE_REGION with your compute region, such as europe-west2.*
  1. Show the configuration.

    gcloud config list
    
  2. Enable APIs in Google Cloud Shell.

    1. Enable Cloud Run.

      run.googleapis.com
      

Deploy to Google Cloud

Deployment

  1. Submit the docker image to Container Registry.

    gcloud builds submit --tag gcr.io/$GOOGLE_CLOUD_PROJECT/website
    
* *Replace PROJECT_ID with your project ID.*
  1. List all container images in this project to verify that the docker image has been submitted successfully.

    gcloud container images list
    
  2. Deploy the Container Image to Cloud Run.

    gcloud run deploy CONTAINER_NAME \
    --image gcr.io/$GOOGLE_CLOUD_PROJECT/DOCKER_IMAGE_NAME:DOCKER_IMAGE_VERSION \
    --platform managed \
    --region GCR_REGION \
    --allow-unauthenticated
    
* *Replace CONTAINER_NAME with the desired Container Name.*

* *Replace DOCKER_IMAGE_NAME with your docker image name.*

* *Replace DOCKER_IMAGE_VERSION with the version of your docker image name.*

* *Replace PROJECT_ID with your project ID.*

* *Replace GCR_REGION with your region, such as europe-west2.*

Here below is a working example:

```shell
gcloud run deploy portfolio-website \
--image gcr.io/$GOOGLE_CLOUD_PROJECT/website:latest \
--platform managed \
--region europe-west1 \
--allow-unauthenticated
```

Verification

  • Check that the web application is running by opening URL of the Cloud Run Service in a web browser.

Check Cloud Run URL in GVP

Verify docker deployment in GCP

References

  1. Source code in GitHub
  2. Live demo at Google Cloud


This content originally appeared on DEV Community and was authored by Ada Cheng


Print Share Comment Cite Upload Translate Updates
APA

Ada Cheng | Sciencx (2022-04-17T15:20:29+00:00) Deploy a Docker image to Google Cloud using Cloud Run. Retrieved from https://www.scien.cx/2022/04/17/deploy-a-docker-image-to-google-cloud-using-cloud-run/

MLA
" » Deploy a Docker image to Google Cloud using Cloud Run." Ada Cheng | Sciencx - Sunday April 17, 2022, https://www.scien.cx/2022/04/17/deploy-a-docker-image-to-google-cloud-using-cloud-run/
HARVARD
Ada Cheng | Sciencx Sunday April 17, 2022 » Deploy a Docker image to Google Cloud using Cloud Run., viewed ,<https://www.scien.cx/2022/04/17/deploy-a-docker-image-to-google-cloud-using-cloud-run/>
VANCOUVER
Ada Cheng | Sciencx - » Deploy a Docker image to Google Cloud using Cloud Run. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/17/deploy-a-docker-image-to-google-cloud-using-cloud-run/
CHICAGO
" » Deploy a Docker image to Google Cloud using Cloud Run." Ada Cheng | Sciencx - Accessed . https://www.scien.cx/2022/04/17/deploy-a-docker-image-to-google-cloud-using-cloud-run/
IEEE
" » Deploy a Docker image to Google Cloud using Cloud Run." Ada Cheng | Sciencx [Online]. Available: https://www.scien.cx/2022/04/17/deploy-a-docker-image-to-google-cloud-using-cloud-run/. [Accessed: ]
rf:citation
» Deploy a Docker image to Google Cloud using Cloud Run | Ada Cheng | Sciencx | https://www.scien.cx/2022/04/17/deploy-a-docker-image-to-google-cloud-using-cloud-run/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.