How to create a dind docker image with azure-cli on Alpine linux?
Asked Answered
F

2

9

I am trying to install the azure-cli in the dind:latest image based on alpine.

For context, I want to use it to connect to AKS and deploy an app to Kubernetes via Gitlab.

In my gitlab-ci.yml file I start with this

image: docker:latest
services:
  - docker:dind

and then I try to install the azure-cli

deploy-to-k8s--dev: # k8s namespace "dev"
  stage: deploy-to-k8s
#  image: microsoft/azure-cli
  script:
    # I need the azure cli in the dind:latest container
    # so install bash,curl and finally the cli
    - apk update
    - apk upgrade
    - apk add bash
    - apk add --no-cache curl

    - curl -L https://aka.ms/InstallAzureCli | bash
    - az

and I get the following error

$ curl -L https://aka.ms/InstallAzureCli | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   167  100   167    0     0    167      0  0:00:01 --:--:--  0:00:01   644

100  1367  100  1367    0     0   1367      0  0:00:01 --:--:--  0:00:01  1367
mktemp: Invalid argument
ERROR: Job failed: error executing remote command: command terminated with non-zero exit code: Error executing in Docker Container: 1

It is the first time that I try to work with Alpine Linux and I have no idea how it is built and what tools it uses...

Has anyone any suggestion?

EDIT

based on the accepted answer this is the final code that works

deploy-to-k8s--dev: # k8s namespace "dev"
  stage: deploy-to-k8s
  script:
    # I need the azure cli in the dind:latest container
    # so install bash,curl and finally the cli
    - apk update
    - apk upgrade
    - apk add bash make py-pip
    - apk add --virtual=build gcc libffi-dev musl-dev openssl-dev python2-dev
    - pip install azure-cli
    - apk del --purge build
    - az -h
Flagellant answered 7/12, 2017 at 16:15 Comment(0)
E
8

This helped me in one of my alpine based image

apk update
apk add bash py-pip
apk add --virtual=build gcc libffi-dev musl-dev openssl-dev python- dev
pip install azure-cli
apk del --purge build
Enrique answered 7/12, 2017 at 16:53 Comment(3)
Thanks, that got me very far but unfortunately I get this error gist.github.com/wehappyfew/9f6d0f4fa09d4eb02a88e8810f942003Flagellant
I added make in the apk add bash py-pip and it's all good !!Flagellant
So for ignorant people like myself, that would be apk add make bash py-pipWhitsuntide
P
4

A relevantly newer version of https://mcmap.net/q/1186043/-how-to-create-a-dind-docker-image-with-azure-cli-on-alpine-linux:

apk add --no-cache --update python3 py3-pip
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==${AZURE_CLI_VERSION}
apk del build

* Remove the AZURE_CLI_VERSION if you want the latest.

Purely answered 14/4, 2023 at 12:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.