Deploy a Go web app to Azure Container Apps

In this quickstart, you'll learn to deploy a containerized Go web app to Azure Container Apps.

Azure Container Apps lets you execute application code packaged in any container without having to manage complicated cloud infrastructure or complex container orchestrators, and without worrying about the runtime or programming model. Common uses of Azure Container Apps include: Deploying API endpoints, hosting background processing applications, handling event-driven processing, and running microservices.

Follow this tutorial to walk through building a Docker image, deploying that image to Azure Container Registry, and deploying a Go web app to Azure Container Apps.

Prerequisites

  • Azure subscription: If you don't have an Azure subscription, create a free account before you begin.

Download the sample app

To follow this tutorial, you'll need a sample application to containerize. A sample Go web app is provided in the msdocs-go-webapp-quickstart GitHub repository. Download or clone the sample application to your local workstation.

git clone https://github.com/Azure-Samples/msdocs-go-webapp-quickstart.git

cd msdocs-go-webapp-quickstart

Create an Azure Container Registry

Azure Container Registry allows you to build, store, and manage container images. You'll use it to store the Docker image that contains the sample Go web app provided in the sample repository mentioned previously.

Run the following commands to create an Azure Container Registry:

  1. Create an Azure resource group.

    az group create \
        --name <resourceGroupName> \
        --location eastus
    
  2. Create an Azure Container Registry.

    az acr create \
        --resource-group <resourceGroupName> \
        --name <azureContainerRegistryName> \
        --sku basic \
        --admin-enabled true
    
  3. Sign in to the Azure container instance.

    az acr login --name <azureContainerRegistryName>  
    

Replace <resourceGroupName> and <azureContainerRegistryName> with the appropriate values. Note that your Azure Container Registry name will need to be globally unique.

Build and push the Docker image

Once you've created an Azure Container Registry, build and push the Docker image of the sample Go web app.

Run the following commands build and push the image to the registry:

  1. Get the sign-in server information.

    az acr show \
        --name <azureContainerRegistryName> \
        --resource-group <resourceGroupName> \
        --query loginServer \
        --output tsv  
    
  2. Build the Docker image locally.

    docker build -t <loginServer>/<imageName>:latest .
    
  3. Push the Docker image to Azure Container Registry.

    docker push <loginServer>/<imageName>:latest
    
  4. Verify the image was successfully pushed to Azure Container Registry.

    az acr repository list \
        --name <azureContainerRegistryName> \
        --output table
    

Replace loginServer, imageName, and azureContainerRegistryName with the appropriate values. The image name is the Docker image that is pushed to Azure Container Registry and later used to deploy to Azure Container Apps.

Now that you've got an image available in Azure Container Registry, you're ready to deploy the Azure Container App and its environment.

Create an Azure Container Apps environment

Azure Container Apps doesn't have the complexity of a container orchestrator, but it still needs some way to establish secure boundaries, which is where Azure Container Apps environments come in. Container Apps deployed in the same environment share the same virtual network and write logs to the same Log Analytics workspace. Before you can deploy an Azure Container App, you'll need an environment to deploy to.

Run the following commands to create an Azure Container Apps environment:

  1. Get the Azure Container Registry admin password.

    ACR_PASSWORD=$(az acr credential show \
        --name <azureContainerRegistryName> \
        --query 'passwords[0].value' \
        --out tsv)
    
  2. Create a Container Apps environment.

    az containerapp env create \
        --name <containerAppEnvName> \
        --resource-group <resourceGroupName> \
        --location "East US"
    

Deploy to Azure Container Apps

At this point, you've created an Azure Container Registry, built, and pushed a Docker image to it, and created an Azure Container Apps environment. All that's left is to deploy the application.

Run the following command to deploy the Go web app to Azure Container Apps:

az containerapp create \
    --name <containerAppName> \
    --resource-group <resourceGroupName> \
    --environment <containerAppEnvName> \
    --image "<loginServer>/<imageName>:latest" \
    --registry-server "<loginServer>" \
    --registry-username "<azureContainerRegistryName>" \
    --registry-password "$ACR_PASSWORD" \
    --target-port 8080 \
    --ingress 'external'

Verify the web app URL

Run the following Azure CLI command to get the FQDN (Fully Qualified Domain Name) of the web application's ingress.

APP_FQDN=$(az containerapp show \
    --name <containerAppName> \
    --resource-group <resourceGroupName> \
    --query properties.configuration.ingress.fqdn \
    --output tsv)

Next, run the curl command against the FQDN and confirm output reflects the HTML of the website.

curl "https://$APP_FQDN"

Clean-up resources

When you're finished with the sample app, you can remove all of the resources for the app from Azure. This avoids on-going charges and keeps your Azure subscription uncluttered. Removing the resource group also removes all resources in the resource group and is the fastest way to remove all Azure resources for your app.

az group delete \
    --name <resourceGroupName> \
    --no-wait

Next steps