-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Install Azure CLI on Alpine Linux #19591
Comments
so we dont think this will work reliably. |
It will. If you see any errors or problems, please reply to this GitHub issue (#19591) with the error message you see. |
These instructions are great and they 100% work, I'm just curious, why not just use the official MS azure-cli image? Seems to already be alpine-based.
|
@OmegaVVeapon With Alpine being an OS, there's a plethora of cloud-provider-agnostic images based on alpine - like postgres:11-alpine, golang:17-alpine etc. Image creators can't (and shouldn't) make decisions about the cloud provider. |
I don't get your point about cloud provider. The Azure CLI docker image is simply using the public Line 8 in 14d5784
The Azure CLI image is not related to Azure as a cloud provider at all. |
I may have misunderstood your comment @OmegaVVeapon What I was trying to say is that these install instructions are helpful/necessary whether or not the For example, if I want Postgres/Alpine/Azure CLI, it makes more sense to do this: FROM postgres:11-alpine
RUN apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo make
RUN pip install azure-cli Rather than to base the image on FROM azure-cli
// [...] |
@sebnyberg, this is exactly why I posted this GitHub issue! 😉 |
Found this, and it works, but I'm wondering why APKs of the CLI haven't simply(?) been made available for download, as there are for other major distros? I don't know Alpine very well; is this a difficult thing to do? |
@dhduvall, this is because Alpine Linux is not as widely used as DEB and RPM. Let me mark this issue as a feature candidate and maybe plan it in the future. |
Thanks for that dokumentation, it helps alot. How ever I still have an issue as our image build server is offline and has only access to external packages like Docker Images, Linux Packages, Python packages to a Nexus OOS proxying the external ressources. Every step works, but Error:
How ever I see on the former step that package installation works fine
Works almost fine. Any idea on that how to avoid this error? |
@Joerg-L, your issue doesn't seem to be caused by Azure CLI, but by Does |
yes, the same issue comes up I have run now which leeds now to
which looks better |
Thanks @Joerg-L for the confirmation. I have updated my original description to include |
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 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 |
@Looooopy, the size-too-big issue of Azure CLI is tracked at #7387. It is mainly due to the size of Azure Python SDKs (Azure/azure-sdk-for-python#11149). We are tightly working with SDK team to reduce the size. Stay tuned! |
Question. Is there not an alpine az-cli that you can just apk add to the image? |
One purpose to use Alpine as docker base image is to save the image size, and less packages, less security concerns But when I saw this line in Dockerfile, install with gcc, musl-dev, python3-dev and make, etc, the size can't be small.
and check its size of the image
only a command with 1.3GB, that surprises me. Any way to improve by Multi-stage builds and this document as well https://rodneyosodo.medium.com/minimizing-python-docker-images-cf99f4468d39
|
Got it. It's quite big. I've managed to construct the image using a multi-stage build, yet the size remains considerable, exceeding 1.2GB
Upon investigation, I discovered that the Azure CLI package itself occupies the majority of the space. This is due to the fact that all versions of the mgmt package are saved and installed together to adapt various versions of the Azure API.
In this example, when install an az network extension with mgmt, the related packages are installed 33 times. This same design applies to other extensions as well, that's the main reason why this Azure-CLI python package is so huge. To reduce the size, we need explore installing only the latest version of the packages, which would significantly decrease the overall size. |
I have tried to address that fact. If you look at the az-cli PRs you will find a packaging PR regarding the Docker build. |
Note that docker images will show the uncompressed size of the image. There is a lot of python code. And... also a lot of |
Install azure cli by python, it works, but so slow to build. |
This is broken since apk currently returns python 3.12 and support isn't there: #27673 you can force APK to use an older repo:
https://pkgs.alpinelinux.org/packages?name=python3-dev*&branch=v3.19&repo=&arch=&maintainer=# |
You can install @jiasli Could we have some reference to e.g. https://github.com/Azure/azure-cli/blob/dev/alpine.dockerfile in the official docs? That there is at least a hint how to do the installation in alpine? |
Full working Dockerfile as 2024-07-27: FROM alpine
RUN apk add py3-pip
RUN apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo make
RUN pip install --break-system-packages --upgrade pip setuptools
RUN pip install --break-system-packages azure-cli |
The big issue here is, a simple command line, the image size is over several GBs. could you confirm it with your way? |
Image build from the Dockerfile that I posted is a bit bellow 3 GB in size. |
Take a look at this image I built (https://hub.docker.com/repository/docker/alpine/azure_cli/general). It's useful for CI/CD pipelines or personal use locally, with a size of less than 1GB.
|
@ozbillwang do you have the sources available somewhere where one does not have to create an account first? |
This may be so, for images running various production workloads. But alpine is extremely widely used for all sorts of jobs and scripts related to infrastructure and operations - which is exactly where |
These instructions don't work any longer with alpine 3.20.3. I haven't checked for previous versions of alpine. You need to use |
FYI that I ended up using the instructions up top in an update to the Azure Pipeline instructions to "Run a self-hosted agent in Docker" on Linux: MicrosoftDocs/azure-devops-docs#14154 |
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
andpython
:Install dependencies
As Alpine Linux is not
manylinux2010
(or greater) compatible, usingpip
to install libraries likecryptography
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 usepip
to install Azure CLI:Use
Dockerfile
Here are the
Dockerfile
s you may use as a starting point:Create
Dockerfile
python:alpine
as base imagealpine
as base imageBuild the image
$ docker build --tag azure-cli-alpine-test .
Run
az
commands$ docker run -it --rm azure-cli-alpine-test az --version
The text was updated successfully, but these errors were encountered: