0
0
GCPcloud~10 mins

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

Choose your learning style9 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.