Today we’ll see how to install Azure-cli in Dockerfile when the base image is Alpine. If you later find this article useful take a look at the disclaimer for information on how to thank me.
As you know azure cli allows you to control azure cloud aspects from command line. This may be useful for provisioning azure resources in ci/cd pipelines or automations, for instance. If the pipelines run inside Jenkins agents (e.g. Docker in Docker Jenkins agent, Podman Jenkins agent) which are containerized, you may need to package azure-cli inside them. Let’s see how to install azure-cli in Dockerfile.
Azure-cli installation in Dockerfile
You probably found it challenging to install Azure-cli as part of Dockerfile where the base image is Alpine.
Use below command sequence to achieve that:
RUN apk add --no-cache --update python3 py3-pip
RUN apk add --no-cache --update --virtual=build gcc musl-dev python3-dev libffi-dev openssl-dev cargo make && pip3 install --no-cache-dir --prefer-binary azure-cli && apk del build
RUN apk add --no-cache --update python3 py3-pip
installed python
and pip
. They are needed because azure-cli is basically Python package.
Second RUN
installs os packages required for successful azure-cli
installation. Then, pip
installs azure-cli
.
See also relevant discussion on GitHub about installation of azure-cli in alpine.
Why apk add –virtual?
Note that these os packages are installed in a virtual
package which is removed after azure-cli
installation using apk del virtual
. This trick reduces the final built image size.
Note also that Azure CLI is a Python package. That’s why it requires Python and Pip to run. Hence these packages are not removed.
See this great answer on stack overflow about apk add --virtual
. Note that apk add --no-cache
reduces image size as well.
Summary
That’s it about Azure-cli installation in Dockerfile when Alpine is a base image.
Find out recommended Azure books on Amazon.
Find out recommended Azure
courses on Pluralsight:
Sign up using this link to get exclusive discounts like 50% off your first month or 15% off an annual subscription)
If you found this article useful, take a look at the disclaimer for information on how to thank me.