DEV Community

Cover image for Deploying a Go Web App on Azure Container Instances with ACR
kristarking
kristarking

Posted on

Deploying a Go Web App on Azure Container Instances with ACR

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 
Enter fullscreen mode Exit fullscreen mode

make directory image

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)
}

Enter fullscreen mode Exit fullscreen mode

golang code image

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"]

Enter fullscreen mode Exit fullscreen mode

dockerfile image

Step 3: Building and Running the Docker Container Locally
To build the Docker image, run:

docker build -t your-image-name:tag .
Enter fullscreen mode Exit fullscreen mode

In my case, I'm using goapp as my image name and v1 as my tag

docker build image
If you have an error like this, don't panic, just open your _Docker Desktop _ then run the command again

docker build image 2

Step 4: Setting Up Azure Container Registry (ACR)
Create an Azure Container Registry (ACR):

Go to Azure console, search for Container Registry

  1. Click Create
  2. Fill in the details:
  3. Subscription: Your Azure Subscription
  4. Resource Group: Create a new one (e.g., goappRG)
  5. Registry Name: A unique name (e.g., kingacr)
  6. Region: Choose a location eg, (Central US)
  7. SKU: Choose Basic (cheapest option) Click Review + Create → Click Create

acr image

Enable Admin Access
Go to your newly created ACR, under "review"
Click Access Keys
Turn on Admin User

azure admin access

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
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

command image

command image 2

command image 3

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

ACI image 1

ACI Image 2

ACI Image 3

Step 7: Accessing the Deployed App
Go to Container Instances
Copy the Public IP Address

ACI Image 4

Open the App in Your Browser
Visit: http://

ACI public ip

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)