Skip to content

Latest commit

 

History

History
77 lines (62 loc) · 3.11 KB

docker-images-acr-aci.md

File metadata and controls

77 lines (62 loc) · 3.11 KB

Docker Image Creation, Azure Container Registry, Azure Container Instances

Prerequisites:

  1. Azure Subscription
  2. Golang installed
  3. Local Docker installed (Linux, Mac or Windows)
  4. Azure CLI installed

Clone the repo

git clone https://github.com/akamenev/aks-workshop.git

Running the app with go run

Inside the cloned repo go to a welcome-app folder and run the app

cd welcome-app
go run main.go

Open http://localhost:8080 in your browser and see the welcome app screen. You can add your name as a GET parameter to change the message - http://localhost:8080?name=Andrei

Building the image with golang base image

Pull the golang image from Dockerhub, build the container and run it

docker pull golang
docker build -t welcome-app-golang:v1 .
docker run -it -p 8080:8080 welcome-app-golang:v1

Try to open a welcome-app again at http://localhost:8080

Building the image with scratch base image

Run the docker images command to see the welcome-app image size. It is more than 800 MB which is pretty big for a small app like that. For a compiled languages we can build a static binary that we can use with a sratch docker image as a base. Open the Dockerfile and Dockerfile.scratch files in editor to see the difference.

Build a Go binary and build a new docker image.

CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main.out main.go

docker build -t welcome-app-scratch:v1 -f Dockerfile.scratch .
docker run -it -p 8080:8080 welcome-app-scratch:v1

Open a welcome-app again at http://localhost:8080 and check the size of the image via docker images

Create an Azure Container Registry

Specify Resource Group and Registry names and create ACR

export RG_NAME=...
export REGISTRY_NAME=...

az login
az group create -n $RG_NAME -l westeurope
az acr create --name $REGISTRY_NAME --resource-group $RG_NAME --sku basic --location westeurope --admin-enabled true

Push the image to the registry

docker tag welcome-app-scratch:v1 $REGISTRY_NAME.azurecr.io/welcome-app:v1
az acr login --name $REGISTRY_NAME
docker push $REGISTRY_NAME.azurecr.io/welcome-app:v1

Build in Azure Container Registry

With ACR you don't even need a docker installed locally, you can build your images using ACR.

az acr build --registry $REGISTRY_NAME --image welcome-app-acrbuild:v1 -f Dockerfile.scratch .

Run in container instance

Run welcome-app on Azure Container Instance

export PASSWORD=$(az acr credential show -n $REGISTRY_NAME --query "passwords[0].value" -o tsv)
export DNS_LABEL=...

az group create -n welcome-app -l westeurope
az container create -n welcome-app -g welcome-app --image "$REGISTRY_NAME.azurecr.io/welcome-app:v1" --registry-username "$REGISTRY_NAME" --registry-password "$PASSWORD" --ports 8080 --dns-name-label $DNS_LABEL