Creating the Dockerfile

Let's write a Dockerfile for Azure CLI.

The first step of any Docker setup is to write its Dockerfile. In the Dockerfile, we’ll specify all the things we need in our container. There are three basic steps to always consider:

  • Make sure your container is running Ubuntu.
  • All frameworks required for your setup are installed in the Dockerfile.
  • Any code you need to run is copied into the container.

Dockerfile

Below, we have provided a basic Dockerfile for Azure CLI. We’ll go through it step-by-step.

Press + to interact
# Base image
FROM ubuntu:20.04
# Packages required to run the Azure CLI installation
RUN apt-get update && apt-get -y install curl
# Azure installation command
RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash

Looks really easy, and it is!

  • FROM ubuntu:20.04 - This specifies the base Docker image that we are using for our container. ubuntu images are officially supported on the platform and hence, ubuntu or other Debian-based images are strongly recommended.

  • RUN apt-get... - Installing curl as it is required for the next step.

  • RUN curl... - The official installation command for Azure CLI (can be found on their website).

Rule of thumb: The installation commands for any framework can be found all over the internet. The trick is to simply copy those commands into your Dockerfile.

Tarball

Once the Dockerfile is ready, you need to compress it into a tarball in order to upload it to your course.

tar -czpf azure.tar.gz Dockerfile

This creates a tarball named azure.tar.gz. You can find the file below:

azure.tar.gz

Uploading the Tarball

This is where you integrate your Docker setup into your course. Navigate to the main course editor page and find the Docker Container section.

The Change Dockerfile button lets you upload the tarball. Click on Save on the top-right to begin the building process! Once the image is built successfully, you will receive the following prompt:


We are almost at the finish line. Head to the next lesson to start using Azure on Educative!