Lädt...

🔧 Deploying a Go Web App on Azure Container Instances with ACR


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

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 

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

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

dockerfile image

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

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

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

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

...

🔧 Deploying a Go Web App on Azure Container Instances with ACR


📈 65.62 Punkte
🔧 Programmierung

🔧 ASP.NET Core Series: Deploying your Microservice to Azure Container Instances | On .NET


📈 36.91 Punkte
🔧 Programmierung

🔧 Automate Docker Build &amp; Push to Azure Container Registry (ACR)


📈 36.49 Punkte
🔧 Programmierung

📰 Azure Container Instances: Vertrauliche Container als Public Preview


📈 34.75 Punkte
📰 IT Nachrichten

📰 Azure Container Instances: Microsofts Serverless Container gehen live


📈 34.75 Punkte
📰 IT Nachrichten

📰 Azure Container Instances startet einzelne Container in der Microsoft Cloud


📈 34.75 Punkte
📰 IT Nachrichten

🔧 Interning in Azure Engineering and the Visual Studio Code extension for ACR Build | Azure Friday


📈 33.86 Punkte
🔧 Programmierung

🎥 Interning in Azure Engineering and the Visual Studio Code extension for ACR Build | Azure Friday


📈 33.86 Punkte
🎥 Video | Youtube

🔧 Best practices for Azure Container Instances (ACI) with GitHub Actions | Azure Friday


📈 32.12 Punkte
🔧 Programmierung

🔧 Azure Container Instances (ACI) under the hood | Azure Friday


📈 32.12 Punkte
🔧 Programmierung

🔧 Code to Cloud with Docker and Azure Container Instances | Azure Friday


📈 32.12 Punkte
🔧 Programmierung

🔧 Serverless containers with Azure Container Instances (ACI) | Azure Friday


📈 32.12 Punkte
🔧 Programmierung

🔧 How to Deploy a FastAPI App to Azure with Docker, ACR, and GitHub Actions


📈 30.93 Punkte
🔧 Programmierung

🎥 Python on Azure: Part 2—Deploying Django services to Azure Web Apps | Azure Friday


📈 29.34 Punkte
🎥 Video | Youtube

🔧 Comparison of Two Methods for Deploying Azure Functions to Azure Container Apps


📈 28.84 Punkte
🔧 Programmierung

🔧 Deploying a Java Azure Function on Azure Container Apps


📈 28.84 Punkte
🔧 Programmierung

🔧 Using Azure Container Registry for building and deploying .NET Core Apps | Azure Friday


📈 28.84 Punkte
🔧 Programmierung

🔧 Unlock the Power of Azure CLI: Push Docker Images to ACR with Ease!


📈 28.51 Punkte
🔧 Programmierung

🔧 Azure Container Instances vs Sliplane


📈 26.77 Punkte
🔧 Programmierung

🎥 Confidential containers on Azure Container Instances (ACI)


📈 26.77 Punkte
🎥 Video | Youtube

📰 CI/CD Pipelines for Data Processing Applications on Azure Part 1: Container Instances


📈 26.77 Punkte
🔧 AI Nachrichten

🎥 Azure Container Instances(ACI) use-cases and roadmap | OD106


📈 26.77 Punkte
🎥 Video | Youtube

📰 Coordinated disclosure of vulnerability in Azure Container Instances Service


📈 26.77 Punkte
📰 IT Security Nachrichten

📰 Coordinated disclosure of vulnerability in Azure Container Instances Service


📈 26.77 Punkte
📰 IT Security Nachrichten