Exercise - Build container images with Azure Container Registry Tasks
Suppose your company makes use of container images to manage compute workloads. You use the local Docker tooling to build your container images.
You can now use Azure Container Registry Tasks to build these containers. Container Registry Tasks also allows for DevOps process integration with automated build on source code commit.
Let's automate the creation of a container image using Azure Container Registry Tasks.
Create a container image with Azure Container Registry Tasks
A standard Dockerfile provides build instructions. Azure Container Registry Tasks allows you to reuse any Dockerfile currently in your environment, including multi-staged builds.
We'll use a new Dockerfile for our example.
You need your own Azure subscription to run this exercise and you may incur charges. If you don't already have an Azure subscription, create a free account before you begin.
The first step is to create a new file named
Dockerfile. You can use any text editor to edit the file. We'll use Cloud Shell Editor for this example.
Enter the following command into the Cloud Shell window to open the editor.
Copy the following contents into the editor.
FROM node:9-alpine ADD https://raw.githubusercontent.com/Azure-Samples/acr-build-helloworld-node/master/package.json / ADD https://raw.githubusercontent.com/Azure-Samples/acr-build-helloworld-node/master/server.js / RUN npm install EXPOSE 80 CMD ["node", "server.js"]
Use the key combination Ctrl+S (Cmd+S for Mac) to save your changes. Name the file
This configuration adds a Node.js application to the
node:9-alpineimage. After that, it configures the container to serve the application on port 80 via the EXPOSE instruction.
Run the following Azure CLI command to build the container image from the Dockerfile. $ACR_NAME is the variable you defined in the preceding unit to hold your container registry name.
az acr build --registry $ACR_NAME --image helloacrtasks:v1 .
Don't forget the period
.at the end of the preceding command. It represents the source directory containing the docker file, which in our case is the current directory. Since we didn't specify the name of a file with the --file parameter, the command looks for a file called Dockerfile in our current directory.
Verify the image
Run the following command in the Cloud Shell to verify that the image has been created and stored in the registry.
az acr repository list --name $ACR_NAME --output table
The output from this command should look similar to the following:
Result ------------- helloacrtasks
helloacrtasks image is now ready to be used.