Install Azure CLI on Alpine Linux
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 3.5k
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 60
Description
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](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli) if it is proven to be useful.
## Azure CLI official docker image
The [official Azure CLI docker image](https://docs.microsoft.com/en-us/cli/azure/run-azure-cli-docker) is built upon Alpine Linux. We recommend using it whenever possible. You may also take the [Dockerfile](https://github.com/Azure/azure-cli/blob/dev/Dockerfile) as a reference.
## Install Azure CLI step-by-step
### Select base image
#### `python:alpine`
The [official Python docker image](https://hub.docker.com/_/python) is preferred as the base image.
```console
$ docker run -it --rm python:alpine sh
```
#### `alpine`
If you would like to use the original [official Alpine docker image](https://hub.docker.com/_/alpine), you need to install `pip` and `python`:
```console
$ 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:
```console
# 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:
```console
# pip install --upgrade pip
# pip install azure-cli
```
## Use `Dockerfile`
Here are the `Dockerfile`s you may use as a starting point:
### Create `Dockerfile`
#### `python:alpine` as base image
```dockerfile
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
```dockerfile
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
```console
$ docker build --tag azure-cli-alpine-test .
```
### Run `az` commands
```console
$ docker run -it --rm azure-cli-alpine-test az --version
```
Contributor guide
Assessment
This issue has not been assessed yet.