Install Azure CLI on Alpine Linux

See original GitHub issue

Users frequently face issues while installing Azure CLI on Alpine Linux docker containers (#7437, #8863, #9167, #4352) , this issue serves as an official installation guide. We will consider moving it to the How to install the Azure CLI official document if it is proven to be useful.

Azure CLI official docker image

The official Azure CLI docker image is built upon Alpine Linux. We recommend using it whenever possible. You may also take the Dockerfile as a reference.

Install Azure CLI step-by-step

Select base image

python:alpine

The official Python docker image is preferred as the base image.

$ docker run -it --rm python:alpine sh

alpine

If you would like to use the original official Alpine docker image, you need to install pip and python:

$ docker run -it --rm alpine
# apk add py3-pip

Install dependencies

As Alpine Linux is not manylinux2010 (or greater) compatible, using pip to install libraries like cryptography will fail without underlying dependencies. Install dependencies with:

# apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo make

See https://cryptography.io/en/latest/installation/#building-cryptography-on-linux

Install Azure CLI

Simply upgrade pip and use pip to install Azure CLI:

# pip install --upgrade pip
# pip install azure-cli

Use Dockerfile

Here are the Dockerfiles you may use as a starting point:

Create Dockerfile

python:alpine as base image

FROM python:alpine
RUN apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo make
RUN pip install --upgrade pip
RUN pip install azure-cli
CMD sh

alpine as base image

FROM alpine
RUN apk add py3-pip
RUN apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo make
RUN pip install --upgrade pip
RUN pip install azure-cli
CMD sh

Build the image

$ docker build --tag azure-cli-alpine-test .

Run az commands

$ docker run -it --rm azure-cli-alpine-test az --version

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:37
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
Looooopycommented, May 7, 2022

Both building from alpine and using it from mcr.microsoft.com/azure-cli:latest make it output image around 1.2GB for something that should be used in cli is awful 😃

Compare it with awscli (amazon/aws-cli) which also is quite heavy 339MB, but why is it getting 3 times larger is my question?

Maybe you think it’s a dumb question but I feel like every image in docker is exploding in storage space!

Here I saved some storage but its only around 200MB, which is made it to the size of mcr.microsoft.com/azure-cli

RUN apk add --no-cache -q --virtual=build gcc musl-dev python3-dev libffi-dev openssl-dev cargo make \
     && pip install --no-cache-dir azure-cli -q \
     && apk del --purge build
4reactions
jiaslicommented, Jan 28, 2022

Thanks @Joerg-L for the confirmation. I have updated my original description to include pip install --upgrade pip.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to install the Azure CLI - Microsoft Learn
To install the Azure CLI on Windows, you must use Powershell, or an MSI installer, which gives you access to the CLI through...
Read more >
How to create a dind docker image with azure-cli on Alpine ...
It is the first time that I try to work with Alpine Linux and I have no idea how it is built and...
Read more >
How to Install Azure CLI (Windows, Linux, macOS, Azure Shell)
Learn how to install Azure CLI on any operating system you have including how to get started using it in the Azure Shell!...
Read more >
Azure CLI by Microsoft | Docker Hub
You can use Docker to run a standalone Linux container with the Azure CLI pre-installed. This image can also be used as a...
Read more >
Running Azure's az command-line tool from a docker container
Pull the Docker image (based on Alpine Linux) for the az CLI tool: docker pull mcr.microsoft.com/azure-cli. Create a docker volume which ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found