Mark Ku's Blog

Introduction

I used to be particularly interested in self-hosting servers, with most of my experience concentrated in on-premises environments. I've worked with everything from self-hosting Windows Server and Linux Server to using Hyper-V and vSphere, and have dabbled in technologies from Windows Docker Containers to Linux Docker Containers. With the development of container technology and the increasing convenience of the cloud, more and more companies are adopting cloud servers, which has sparked my interest in further exploring the possibilities of cloud deployment.

On-Premises vs. Cloud Container Deployment Flow

  • On-Premises Deployment Flow
    Docker Build Image → Push Image to Private Registry → Docker Run

  • Cloud Deployment Flow
    Docker Build Image → Push Image to Google Artifact Registry → Google Cloud Run

Environment Setup

  • Operating System: Windows 11, with Docker Desktop installed locally.
  • A containerizable project with a pre-existing Dockerfile.
  • GCP Project ID: gcr-my-project01 Link to get your Project ID
  • Google Artifact Registry host location: asia-east1-docker.pkg.dev (Found in Artifact Registry > Check your Registry > Setup Instructions)

Installing the Google Cloud CLI

  1. Download and install the Google Cloud CLI
(New-Object Net.WebClient).DownloadFile("https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe", "$env:Temp\GoogleCloudSDKInstaller.exe")
& $env:Temp\GoogleCloudSDKInstaller.exe
  1. During the Windows installation, an installation window will pop up. Just follow the prompts and click "Next" all the way through.
  2. After installation, you will be asked if you want to log in and select a Google project (of course, you can also log in via the command line, e.g., gcloud auth login). gcp cli sign
gcloud auth login
gcloud projects list
gcloud config set project PROJECT_ID

Creating an Artifact Registry

Go to Artifact Registry and get the URL for your registry.

  1. Create a repository Create repository

  2. Make minor adjustments to the default settings > Create artifact registry settings

  3. Select the created registry > Setup instructions > Copy the configuration command get local's set up command Note: Windows users should remove \ to make the command a single line.

  4. Configure Google Artifact Registry on your local machine:

gcloud auth configure-docker asia-east1-docker.pkg.dev
Screen after setup
Screen after setup

Building and Verifying the Docker Image

  1. First, use the command line to navigate to your containerizable project, which should already have a Dockerfile.
  2. Use the following command to build the Docker image:
docker build -t asia-east1-docker.pkg.dev/gcr-my-project01/my-registry/ec:v2 .
  1. Run the image to test it locally:
docker run -d -p 8888:80 asia-east1-docker.pkg.dev/gcr-my-project01/my-registry/ec:v2
  1. Visit localhost:8888 to test the container service and check for any issues. local container testing

Pushing the Image to Artifact Registry

docker push asia-east1-docker.pkg.dev/gcr-my-project01/my-registry/ec:v2

At this point, you should be able to see the Docker image you just pushed in your registry. check registry

Deploying to Google Cloud Run

Google Cloud Run supports both manual deployment via the web UI and deployment using command-line scripts.

Manual Deployment from the Web UI

  1. In Cloud Run, select "+Deploy Container". manual deploy google cloud run step 1

  2. Follow the on-screen instructions to complete the setup. manual deploy google cloud run step 2

  3. Go into Cloud Run, configure parameters like Container(s), Volumes, Networking, and Security, and set the Container port to 80. manual deploy google cloud run step 3

Alternatively, Deploy to Cloud Run Using a Script

gcloud run deploy my-service --image=asia-east1-docker.pkg.dev/gcr-my-project01/my-registry/ec:v2 --platform managed --allow-unauthenticated --region=asia-east1 --port=80

Automated deployment - screen after execution Now, visit this URL to check your container application. You can also see the status of this container service in Google Cloud Run.

Conclusion

After using the GCP CLI, I found that its operation is quite similar to on-premises commands, which significantly lowered the learning curve. For small and medium-sized enterprises, a cloud tool like this is particularly attractive. It not only eliminates the cost of purchasing physical servers but also removes the hassle of software updates. For a smaller company where the daily maintenance workload isn't enough to justify a full-time network administrator, GCP's flexible plans allow us to scale resources up or down as needed, enabling more agile use of our IT budget.

Addendum - Updating an Image by Redeploying the Service

Method 1: Update the Image Using the Google Cloud Console Website

  1. Go to the Google Cloud Console.
  2. Navigate to Cloud Run.
  3. Click on the service you want to update.
  4. Click EDIT AND DEPLOY NEW REVISION or Deploy New Revision.
  5. In the Container image URL field, enter the new container image (e.g., gcr.io/<project-id>/<image-name>:<tag>).
  6. Configure other settings (if needed), then click Deploy.

Method 2: Update the Image Using the gcloud CLI

If you are using the command-line tool, you can use the gcloud run deploy command to update the image:

gcloud run deploy <SERVICE_NAME> \
  --image gcr.io/<PROJECT_ID>/<ARTIFACT_REGISTRY_URL>/<IMAGE_NAME>:<TAG> \
  --region <REGION>

References

Author

Mark Ku

擁有 10+ 年經驗的資深軟體工程師,現為 AI 應用 Builder,專注於大型平台架構與簡化複雜系統設計,從電商系統到訂閱與收費平台,結合 AI Agent、AI 整合與自動化開發,打造高效率且可持續演進的產品技術基礎。Read More

Found this useful?

The author's free tools, daily podcasts and newsletter are all here.

Mark Ku · This article is licensed under CC BY 4.0. Credit the author and link back to the original when reusing it.

Comments

Subscribe to Newsletter

Subscribe to get new posts delivered instantly — never miss a tech share.

By submitting, you agree to receive emails. You can anytime.

Popular Posts

View all
Mark Ku
··602

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution
Mark Ku
··490

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.
Mark Ku
··333

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki
Mark Ku
··264

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning
Mark Ku
··221

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1
Mark Ku
··215

Setting Up Samba on Ubuntu to Share Folders with Windows 11

Setting Up Samba on Ubuntu to Share Folders with Windows 11