Bird
Raised Fist0
GCPcloud~10 mins

Deploying container images in GCP - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Deploying container images
Write Dockerfile
↓
Build container image
↓
Tag image for registry
↓
Push image to Container Registry
↓
Create deployment using image
↓
Service starts running container
↓
Monitor and update deployment
This flow shows how you create a container image, upload it to Google Container Registry, and deploy it to run as a service.
Execution Sample
GCP
docker build -t gcr.io/my-project/my-app:v1 .
docker push gcr.io/my-project/my-app:v1
gcloud run deploy my-app --image gcr.io/my-project/my-app:v1 --region us-central1
Builds a container image, pushes it to Google Container Registry, and deploys it to Cloud Run.
Process Table
StepActionInput/CommandResult/Output
1Build container imagedocker build -t gcr.io/my-project/my-app:v1 .Image 'gcr.io/my-project/my-app:v1' created locally
2Push image to registrydocker push gcr.io/my-project/my-app:v1Image uploaded to Google Container Registry
3Deploy container imagegcloud run deploy my-app --image gcr.io/my-project/my-app:v1 --region us-central1Cloud Run service 'my-app' deployed and running
4Verify deploymentgcloud run services describe my-app --region us-central1Service status: Ready, URL available
5Update deploymentdocker build -t gcr.io/my-project/my-app:v2 .New image 'gcr.io/my-project/my-app:v2' built locally
6Push updated imagedocker push gcr.io/my-project/my-app:v2Image 'v2' uploaded to registry
7Deploy updated imagegcloud run deploy my-app --image gcr.io/my-project/my-app:v2 --region us-central1Service updated to use image 'v2'
8Verify updategcloud run services describe my-app --region us-central1Service status: Ready, running updated image
9ExitN/ADeployment complete and running
💡 Deployment is complete when the service status is Ready and running the desired container image.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 5After Step 6After Step 7Final
Container Image TagNonegcr.io/my-project/my-app:v1 (built)gcr.io/my-project/my-app:v1 (pushed)gcr.io/my-project/my-app:v1 (deployed)gcr.io/my-project/my-app:v2 (built)gcr.io/my-project/my-app:v2 (pushed)gcr.io/my-project/my-app:v2 (deployed)gcr.io/my-project/my-app:v2 (running)
Service StatusNoneNoneNoneReady (running v1)Ready (running v1)Ready (running v1)Ready (running v2)Ready (running v2)
Key Moments - 3 Insights
Why do we tag the container image before pushing it?
Tagging names the image with the registry path so it knows where to upload. See execution_table step 1 and 2 where the image is built with a tag and then pushed.
What happens if the deployment command uses an image tag that is not pushed?
The deployment will fail because the image is not found in the registry. The image must be pushed first as shown in step 2 before deploying in step 3.
How do we update the running service with a new container version?
Build and push a new image with a new tag (steps 5 and 6), then deploy again with the new image tag (step 7). The service status updates accordingly (step 8).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the container image tag after step 3?
ANone
Bgcr.io/my-project/my-app:v1 (deployed)
Cgcr.io/my-project/my-app:v2 (built)
Dgcr.io/my-project/my-app:v2 (deployed)
💡 Hint
Check the 'Container Image Tag' row in variable_tracker after step 3.
At which step does the service start running the updated container image?
AStep 7
BStep 3
CStep 5
DStep 2
💡 Hint
Look at the 'Service Status' variable in variable_tracker after step 7.
If you skip pushing the image (step 2), what will happen at deployment (step 3)?
ADeployment succeeds with local image
BDeployment uses previous image automatically
CDeployment fails due to missing image in registry
DDeployment ignores image tag
💡 Hint
Refer to key_moments explanation about pushing images before deployment.
Concept Snapshot
Deploy container images by:
1. Building image locally with a tag for registry
2. Pushing image to Google Container Registry
3. Deploying image to Cloud Run or other service
4. Updating by repeating build, push, deploy with new tag
Always push before deploy to avoid errors.
Full Transcript
Deploying container images in Google Cloud involves building a container image locally using Docker, tagging it with the registry path, pushing it to Google Container Registry, and then deploying it to a service like Cloud Run. The deployment command uses the image tag to pull the image from the registry and run it. To update the service, build and push a new image with a new tag, then deploy again with that tag. The service status changes to Ready when running the container. Skipping the push step causes deployment failure because the image is not found in the registry.

Practice

(1/5)
1. What is the main purpose of deploying a container image on Google Cloud Run?
easy
A. To run applications without managing servers
B. To create virtual machines manually
C. To store data in a database
D. To write code directly in the cloud console

Solution

  1. Step 1: Understand what Cloud Run does

    Cloud Run runs containerized apps without needing you to manage servers.
  2. Step 2: Compare options to Cloud Run's purpose

    Options B, C, and D describe other cloud tasks, not Cloud Run's main use.
  3. Final Answer:

    To run applications without managing servers -> Option A
  4. Quick Check:

    Cloud Run = serverless app running [OK]
Hint: Cloud Run runs apps without servers [OK]
Common Mistakes:
  • Confusing Cloud Run with VM creation
  • Thinking Cloud Run stores data
  • Assuming Cloud Run is a coding environment
2. Which command correctly deploys a container image to Cloud Run in the us-central1 region?
easy
A. gcloud deploy run myapp --image=gcr.io/myproject/myimage --zone=us-central1
B. gcloud run deploy myapp --image=gcr.io/myproject/myimage --region=us-central1
C. gcloud run create myapp --image=gcr.io/myproject/myimage --zone=us-central1
D. gcloud run deploy --image=myimage gcr.io/myproject --region=us-central1

Solution

  1. Step 1: Identify correct gcloud command syntax

    The correct command is 'gcloud run deploy' followed by service name, image, and region.
  2. Step 2: Check each option for syntax errors

    gcloud run deploy myapp --image=gcr.io/myproject/myimage --region=us-central1 matches correct syntax. Options B, C, and D have wrong commands or argument order.
  3. Final Answer:

    gcloud run deploy myapp --image=gcr.io/myproject/myimage --region=us-central1 -> Option B
  4. Quick Check:

    Correct deploy syntax = gcloud run deploy myapp --image=gcr.io/myproject/myimage --region=us-central1 [OK]
Hint: Use 'gcloud run deploy' with --image and --region [OK]
Common Mistakes:
  • Using 'gcloud deploy run' instead of 'gcloud run deploy'
  • Confusing --zone with --region
  • Incorrect argument order
3. Given this command:
gcloud run deploy myservice --image=gcr.io/myproj/app:v1 --region=us-east1
What happens after running it?
medium
A. The container image is deployed as a Cloud Run service named 'myservice' in us-east1 region
B. A virtual machine named 'myservice' is created in us-east1
C. The image is uploaded to Google Container Registry only
D. The command fails because region must be us-central1

Solution

  1. Step 1: Understand the deploy command effect

    The command deploys the container image as a Cloud Run service with the given name and region.
  2. Step 2: Evaluate other options

    B is wrong because no VM is created. C is wrong because deployment runs the image, not just upload. A is wrong because us-east1 is a valid region.
  3. Final Answer:

    The container image is deployed as a Cloud Run service named 'myservice' in us-east1 region -> Option A
  4. Quick Check:

    Deploy command = service deployment [OK]
Hint: Deploy runs container as service, not VM or just upload [OK]
Common Mistakes:
  • Thinking deploy creates VM
  • Confusing upload with deploy
  • Assuming region must be us-central1
4. You run:
gcloud run deploy --image=gcr.io/myproj/app:v2 --region=us-west1
But get an error: "Service name is required." What is the fix?
medium
A. Remove the --region flag
B. Change --image to --container-image
C. Add the service name after 'deploy', e.g., 'gcloud run deploy myservice ...'
D. Run the command without 'gcloud run'

Solution

  1. Step 1: Identify missing required argument

    The error says service name is missing; the deploy command needs a service name after 'deploy'.
  2. Step 2: Fix the command by adding service name

    Add the service name, e.g., 'myservice', after 'deploy' to fix the error.
  3. Final Answer:

    Add the service name after 'deploy', e.g., 'gcloud run deploy myservice ...' -> Option C
  4. Quick Check:

    Deploy needs service name [OK]
Hint: Always specify service name after 'deploy' [OK]
Common Mistakes:
  • Omitting service name
  • Changing unrelated flags
  • Removing required command parts
5. You want to deploy a new version of your app container image to Cloud Run and keep the same service URL. Which command should you use?
hard
A. gcloud container deploy myapp --image=gcr.io/myproj/app:v2
B. gcloud run create myapp --image=gcr.io/myproj/app:v2 --region=us-central1
C. gcloud run deploy --image=gcr.io/myproj/app:v2 --region=us-central1
D. gcloud run deploy myapp --image=gcr.io/myproj/app:v2 --region=us-central1

Solution

  1. Step 1: Understand updating a Cloud Run service

    To update an existing service and keep its URL, use 'gcloud run deploy' with the same service name.
  2. Step 2: Check options for correct update command

    gcloud run deploy myapp --image=gcr.io/myproj/app:v2 --region=us-central1 uses 'deploy' with service name and new image, which updates the service. Options A, B, and D are incorrect commands or missing service name.
  3. Final Answer:

    gcloud run deploy myapp --image=gcr.io/myproj/app:v2 --region=us-central1 -> Option D
  4. Quick Check:

    Deploy with same service name updates app [OK]
Hint: Use 'deploy' with same service name to update [OK]
Common Mistakes:
  • Using 'create' instead of 'deploy' to update
  • Omitting service name
  • Using wrong gcloud commands
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard