We will use Azure COntainer Registry to build our containers from Dockerfiles and also host our images to run in AKS
-
In the browser, sign in to the Azure portal at https://portal.azure.com. Your Azure login ID will look something like
[email protected]
-
Click "Create a resource" and select "Container Registry"
-
Provide a name for your registry (this must be unique)
-
Use the existing Resource Group
-
Enable the Admin user
-
Use the 'Standard' SKU (default)
The Standard registry offers the same capabilities as Basic, but with increased storage limits and image throughput. Standard registries should satisfy the needs of most production scenarios.
-
Open the Azure Cloud Shell
-
The first time Cloud Shell is started will require you to create a storage account. In our lab, you must click
Advanced
and enter an account name and share. -
Once your cloud shell is started, clone the workshop repo into the cloud shell environment
git clone https://github.com/Azure/blackbelt-aks-hackfest.git
-
In the cloud shell, you are automatically logged into your Azure subscription.
az login
is not required. -
Verify your subscription is correctly selected as the default
az account list
-
Find your RG name
az group list
[ { "id": "/subscriptions/b23accae-e655-44e6-a08d-85fb5f1bb854/resourceGroups/ODL-aks-v2-gbb-8386", "location": "centralus", "managedBy": null, "name": "ODL-aks-v2-gbb-8386", "properties": { "provisioningState": "Succeeded" }, "tags": { "AttendeeId": "8391", "LaunchId": "486", "LaunchType": "ODL", "TemplateId": "1153" } } ]
For the first container, we will be creating a Dockerfile from scratch. For the other containers, the Dockerfiles are provided.
-
Create a Dockerfile
-
Access the cloud shell
-
In the
~/blackbelt-aks-hackfest/app/web
directory, add a file called "Dockerfile"- you can add an empty file by running
touch Dockerfile
in the cloud shell. - you can launch in in-browser code editor in cloud shell by typing
code .
at the bash prompt (click the refresh button to see the new Dockerfile)
- you can add an empty file by running
-
Add the following lines and save:
FROM node:9.4.0-alpine ARG VCS_REF ARG BUILD_DATE ARG IMAGE_TAG_REF ENV GIT_SHA $VCS_REF ENV IMAGE_BUILD_DATE $BUILD_DATE ENV IMAGE_TAG $IMAGE_TAG_REF WORKDIR /usr/src/app COPY package*.json ./ RUN npm install COPY . . RUN apk --no-cache add curl EXPOSE 8080 CMD [ "npm", "run", "container" ]
-
-
Create a container image for the node.js Web app
From the terminal session:
cd ~/blackbelt-aks-hackfest/app/web # Set environment variable for ACR Name ACR_NAME=<registry-name> az acr build --registry $ACR_NAME --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` --build-arg VCS_REF=`git rev-parse --short HEAD` --build-arg IMAGE_TAG_REF=v1 --image azureworkshop/rating-web:v1 .
- Return to the Azure Portal in your browser and validate that the image appears in your Container Registry under the "Repositories" area.
- Under tags, you will see "v1" listed.
In this step, the Dockerfile has been created for you.
-
Create a container image for the node.js API app
cd ~/blackbelt-aks-hackfest/app/api az acr build --registry $ACR_NAME --image azureworkshop/rating-api:v1 .
- Return to the Azure Portal in your browser and validate that the image appears in your Container Registry under the "Repositories" area.
- Under tags, you will see "v1" listed.
-
Create a MongoDB image with data files
cd ~/blackbelt-aks-hackfest/app/db az acr build --registry $ACR_NAME --image azureworkshop/rating-db:v1 .
- Return to the Azure Portal in your browser and validate that the image appears in your Container Registry under the "Repositories" area.
- Under tags, you will see "v1" listed.