Table of Contents
Introduction
Requirements
Step 1: Writing the Go Web App
Step 2: Creating the Dockerfile
Step 3: Building and Running the Docker Container Locally
Step 4: Setting Up Azure Container Registry (ACR)
Step 5: Pushing the Docker Image to ACR
Step 6: Deploying the Container to Azure Container Instances (ACI)
Step 7: Accessing the Deployed App
Conclusion
Introduction
Cloud-native applications are revolutionizing the way we deploy and scale software. In this guide, we will build a simple Go-based web app, containerize it using Docker, push the image to Azure Container Registry (ACR), and finally deploy it on Azure Container Instances (ACI).
By the end, you will have a fully functional cloud-hosted app running on Azure.
Requirements
Before we begin, ensure you have the following:
✅ Azure CLI installed → Install Azure CLI
✅ Docker installed → Install Docker
✅ Go installed → Install Go
✅ An Azure Subscription (Create one at Azure Portal
Step 1: Writing the Go Web App
First, create a new directory and navigate into it: Open any terminal you have use this command
mkdir go-app && cd go-app
Now, open your VS code and create a file name _main.go _and add the following Go code:
package main import ( "fmt" "net/http" "os" ) func main() { version := os.Getenv("VERSION") if version == "" { version = "v1" // Default version } http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, `<html> <head> <title>Cloud DevOps in Action</title> <style> body { font-family: Arial, sans-serif; text-align: center; margin-top: 50px; } h1 { color: #2c3e50; } h2 { color: #16a085; } p { color: #7f8c8d; font-size: 18px; } </style> </head> <body> <h1>🚀 Welcome to Cloud DevOps in Action! 🌍</h1> <h2>Continuous Deployment. Scalable. Resilient.</h2> <p>Empowering developers and businesses with automated deployments.</p> <p>Running Version: %s</p> <p>🔹 Powered by Containers | Kubernetes | GitHub Actions | Azure 🔹</p> <p><i>Stay ahead in the cloud revolution! 🚀</i></p> </body> </html>`, version) }) http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "App Version: %s\n", version) }) http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "System Status: Healthy ✅\n") }) fmt.Println("Server running on port 80...") http.ListenAndServe(":80", nil) }
Step 2: Creating the Dockerfile
Next, create a Dockerfile in the same directory:
FROM golang:alpine AS builder ARG VERSION ENV VERSION=${VERSION:-v2} WORKDIR /app COPY main.go . RUN go build -o app main.go FROM alpine:latest WORKDIR /app COPY --from=builder /app/app . EXPOSE 80 CMD ["./app"]
Step 3: Building and Running the Docker Container Locally
To build the Docker image, run:
docker build -t your-image-name:tag .
In my case, I'm using goapp as my image name and v1 as my tag
If you have an error like this, don't panic, just open your _Docker Desktop _ then run the command again
Step 4: Setting Up Azure Container Registry (ACR)
Create an Azure Container Registry (ACR):
Go to Azure console, search for Container Registry
- Click Create
- Fill in the details:
- Subscription: Your Azure Subscription
- Resource Group: Create a new one (e.g., goappRG)
- Registry Name: A unique name (e.g., kingacr)
- Region: Choose a location eg, (Central US)
- SKU: Choose Basic (cheapest option) Click Review + Create → Click Create
Enable Admin Access
Go to your newly created ACR, under "review"
Click Access Keys
Turn on Admin User
Step 5: Uploading the Docker Image to ACR
Log in to ACR from Docker using this command
az acr login --name youracrname docker build . -t youracr.azurecr.io/your-image-name:v1
In my case I'm using goapp as image name and my ACR is kingacr
Push the Image to ACR
docker push youracr.azurecr.io/your-image-name:v1
Step 6: Deploying the Container to Azure Container Instances (ACI)
Go to Azure Portal
Search for Container Instances
Configure ACI Deployment
Resource Group: e.g goappRG
Container Name:e.g cloud-devops-container
Region: Same as ACR
Image Source: Select Azure Container Registry
Registry Name: kingacr
Image: e.g go-app
OS Type: Linux
CPU: 1
Memory: 1GB
Port: 80
Click Review + Create → Create
Step 7: Accessing the Deployed App
Go to Container Instances
Copy the Public IP Address
Open the App in Your Browser
Visit: http://
Conclusion
In this guide, we walked through the entire process of building, containerizing, and deploying a Go web application using Azure Container Registry (ACR) and Azure Container Instances (ACI)—all through the Azure Portal without needing complex CLI commands.
🌟 What You Achieved Today:
✅ Developed a simple yet powerful cloud-native Go application
✅ Containerized the app using Docker for seamless portability
✅ Configured and pushed the image to Azure Container Registry (ACR)
✅ Deployed it as a fully managed container instance (ACI)
✅ Accessed the live application via a public endpoint
Top comments (0)