DEV Community

Cover image for Part-120: 🚀Build, Push, and Deploy a Docker Image to Google Artifact Registry on Google Kubernetes Engine
Latchu@DevOps
Latchu@DevOps

Posted on

Part-120: 🚀Build, Push, and Deploy a Docker Image to Google Artifact Registry on Google Kubernetes Engine

In this tutorial, we’ll walk through the complete workflow of building a Docker image, pushing it to Google Artifact Registry, and deploying it on a Google Kubernetes Engine (GKE) cluster.

This hands-on guide is great for anyone learning containerization, Artifact Registry, or Kubernetes deployments on Google Cloud.

a0


🧠 What You’ll Learn

By the end of this tutorial, you’ll be able to:

  • Build and test a Docker image locally
  • Create and configure a Google Artifact Repository
  • Push Docker images securely to Artifact Registry
  • Deploy an application on GKE using Artifact Registry images
  • Access and verify your running app via a LoadBalancer service

🪜 Step 1: Introduction

Here’s the overall workflow we’ll follow:

  1. Build a Docker Image
  2. Create a Docker repository in Google Artifact Registry
  3. Set up authentication
  4. Push the image to the repository
  5. Pull the image in a GKE Deployment
  6. Access and verify the sample application in a browser

🧱 Step 2: Create a Dockerfile

Let’s create our first project directory and define a simple Nginx-based Docker image.

mkdir 01-Docker-Image
cd 01-Docker-Image
Enter fullscreen mode Exit fullscreen mode

Dockerfile

FROM nginx
COPY index.html /usr/share/nginx/html
Enter fullscreen mode Exit fullscreen mode

index.html

<!DOCTYPE html>
<html>
   <body style="background-color:rgb(185, 126, 120);">
      <h1>Welcome to Latchu@DevOps</h1>
      <p>Google Kubernetes Engine</p>
      <p>Google Artifact Registry - Demo</p>
      <p>Application Version: V1</p>
   </body>
</html>
Enter fullscreen mode Exit fullscreen mode

🏗️ Step 3: Build the Docker Image

a1

# Change directory
cd 01-Docker-Image

# Build Docker image
docker build -t myapp1:v1 .

# List Docker images
docker images myapp1
Enter fullscreen mode Exit fullscreen mode

a2


🧪 Step 4: Run and Test the Image Locally

# Run the image
docker run --name myapp1 -p 80:80 -d myapp1:v1

# Access in browser or via curl
curl http://localhost

# Check running containers
docker ps

# Stop and remove container
docker stop myapp1
docker rm myapp1
Enter fullscreen mode Exit fullscreen mode

a3

At this point, your application should work locally.
Now let’s host it on Google Artifact Registry.


🗂️ Step 5: Create a Google Artifact Registry

In the Google Cloud Console:

Go to Artifact Registry → Repositories → Create

Configure as follows:

  • Name: gke-artifact-repo1
  • Format: Docker
  • Mode: Standard
  • Region: us-central1
  • Encryption: Google-managed key
  • Cleanup Policies: Default (dry run)

Click Create

a4


🔐 Step 6: Configure Authentication

To push Docker images to Artifact Registry, configure authentication.

# Configure authentication for your region
gcloud auth configure-docker us-central1-docker.pkg.dev
Enter fullscreen mode Exit fullscreen mode

If you’re using Cloud Shell, authentication is already set up.

a5


🚢 Step 7: Tag and Push Docker Image to Artifact Registry

Tag your local Docker image with the Artifact Registry path and push it:

# Tag the Docker Image
docker tag myapp1:v1 <LOCATION>-docker.pkg.dev/<GOOGLE-PROJECT-ID>/<GOOGLE-ARTIFACT-REGISTRY-NAME>/<IMAGE-NAME>:<IMAGE-TAG>

# Replace Values for docker tag command 
# - LOCATION, 
# - GOOGLE-PROJECT-ID, 
# - GOOGLE-ARTIFACT-REGISTRY-NAME, 
# - IMAGE-NAME, 
# - IMAGE-TAG
# Tag your Docker image

docker tag myapp1:v1 us-central1-docker.pkg.dev/gcp-zero-to-hero-468909/gke-artifact-repo1/myapp1:v1

# Authenticate to Google Cloud (if not done)
gcloud auth login

# Push the image
docker push us-central1-docker.pkg.dev/gcp-zero-to-hero-468909/gke-artifact-repo1/myapp1:v1
Enter fullscreen mode Exit fullscreen mode

a6


🔍 Step 8: Verify the Image in Artifact Registry

Go to Google Cloud Console → Artifact Registry → gke-artifact-repo1,
and verify that your image (myapp1:v1) is successfully uploaded.

a7


☸️ Step 9: Deploy to GKE Using Artifact Registry Image

Now, let’s create Kubernetes manifests to deploy our image from Artifact Registry.

mkdir 02-kube-manifests-art
cd 02-kube-manifests-art
Enter fullscreen mode Exit fullscreen mode

01-kubernetes-deployment.yaml

apiVersion: apps/v1
kind: Deployment 
metadata: 
  name: myapp1-deployment
spec: 
  replicas: 2
  selector:
    matchLabels:
      app: myapp1
  template:  
    metadata: 
      name: myapp1-pod
      labels: 
        app: myapp1  
    spec:
      containers:
        - name: myapp1-container
          image: us-central1-docker.pkg.dev/gcp-zero-to-hero-468909/gke-artifact-repo1/myapp1:v1
          ports: 
            - containerPort: 80
Enter fullscreen mode Exit fullscreen mode

02-kubernetes-loadBalancer-service.yaml

apiVersion: v1
kind: Service 
metadata:
  name: myapp1-lb-service
spec:
  type: LoadBalancer
  selector:
    app: myapp1
  ports: 
    - name: http
      port: 80
      targetPort: 80
Enter fullscreen mode Exit fullscreen mode

🚀 Step 10: Deploy and Verify on GKE

a8

# Apply the manifests
kubectl apply -f 02-kube-manifests-art

# Check deployments and pods
kubectl get deploy
kubectl get pods

# Describe Pod (to confirm image source)
kubectl describe pod <POD-NAME>
Enter fullscreen mode Exit fullscreen mode

You should see an event similar to this:

Pulling image "us-central1-docker.pkg.dev/gcp-zero-to-hero-468909/gke-artifact-repo1/myapp1:v1"
Successfully pulled image "us-central1-docker.pkg.dev/gcp-zero-to-hero-468909/gke-artifact-repo1/myapp1:v1"
Enter fullscreen mode Exit fullscreen mode

a9

Now check the service:

kubectl get svc
Enter fullscreen mode Exit fullscreen mode

Copy the EXTERNAL-IP of the LoadBalancer and open it in your browser:

http://<SVC-EXTERNAL-IP>
Enter fullscreen mode Exit fullscreen mode

a10

🎉 Your app is now live on GKE, pulling images from Artifact Registry!


🧹 Step 11: Clean Up

# Delete deployed resources
kubectl delete -f 02-kube-manifests-art
Enter fullscreen mode Exit fullscreen mode

🏁 Wrapping Up

In this tutorial, we’ve:

✅ Built and tested a Docker image locally
✅ Created a Google Artifact Registry
✅ Pushed an image securely to GAR
✅ Deployed the image to GKE via Kubernetes manifests

Google Artifact Registry is now the recommended and future-ready solution for container image management — replacing the older Google Container Registry (GCR).


🌟 Thanks for reading! If this post added value, a like ❤️, follow, or share would encourage me to keep creating more content.


— Latchu | Senior DevOps & Cloud Engineer

☁️ AWS | GCP | ☸️ Kubernetes | 🔐 Security | ⚡ Automation
📌 Sharing hands-on guides, best practices & real-world cloud solutions

Top comments (0)