Skip to content
Advertisement

Can’t install bash in multiarch build on Alpine

I am trying to build image for linux/arm64/v8 on linux/amd64 Gitlab runner. I run it with this command:

docker buildx create --use
docker buildx build --platform linux/arm64/v8 -f Dockerfile.dev -t registry.gitlab.com/xxx:yyy --build-arg ENV=dev --build-arg COMPOSER_AUTH_FILE=./auth.json .

My Dockerfile is fairly simple:

FROM alpine:latest

RUN apk update && 
    apk add --no-cache composer git bash openssh-client patch && 
    apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev

But it fails with:

#6 [2/2] RUN apk update &&     apk add --no-cache composer git bash openssh-client patch &&     apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev
#6 0.185 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/aarch64/APKINDEX.tar.gz
#6 0.832 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/aarch64/APKINDEX.tar.gz
#6 1.679 v3.14.2-119-g9c4e1aa60c [https://dl-cdn.alpinelinux.org/alpine/v3.14/main]
#6 1.679 v3.14.2-120-g90167408c8 [https://dl-cdn.alpinelinux.org/alpine/v3.14/community]
#6 1.679 OK: 14818 distinct packages available
#6 1.828 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/aarch64/APKINDEX.tar.gz
#6 2.263 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/aarch64/APKINDEX.tar.gz
#6 2.977 (1/31) Installing ncurses-terminfo-base (6.2_p20210612-r0)
#6 3.010 (2/31) Installing ncurses-libs (6.2_p20210612-r0)
#6 3.049 (3/31) Installing readline (8.1.0-r0)
#6 3.075 (4/31) Installing bash (5.1.4-r0)
#6 3.137 Executing bash-5.1.4-r0.post-install
#6 3.144 ERROR: bash-5.1.4-r0.post-install: script exited with error 1
#6 3.144 (5/31) Installing php7-common (7.4.25-r0)
#6 3.159 (6/31) Installing argon2-libs (20190702-r1)
#6 3.171 (7/31) Installing libedit (20210216.3.1-r0)
#6 3.190 (8/31) Installing pcre2 (10.36-r0)
#6 3.225 (9/31) Installing xz-libs (5.2.5-r0)
#6 3.244 (10/31) Installing libxml2 (2.9.12-r1)
#6 3.308 (11/31) Installing php7 (7.4.25-r0)
#6 3.503 (12/31) Installing php7-phar (7.4.25-r0)
#6 3.527 (13/31) Installing ca-certificates (20191127-r5)
#6 3.575 (14/31) Installing brotli-libs (1.0.9-r5)
#6 3.620 (15/31) Installing nghttp2-libs (1.43.0-r0)
#6 3.638 (16/31) Installing libcurl (7.79.1-r0)
#6 3.674 (17/31) Installing php7-curl (7.4.25-r0)
#6 3.690 (18/31) Installing php7-iconv (7.4.25-r0)
#6 3.702 (19/31) Installing php7-json (7.4.25-r0)
#6 3.716 (20/31) Installing oniguruma (6.9.7.1-r0)
#6 3.747 (21/31) Installing php7-mbstring (7.4.25-r0)
#6 3.815 (22/31) Installing php7-openssl (7.4.25-r0)
#6 3.833 (23/31) Installing libzip (1.7.3-r2)
#6 3.849 (24/31) Installing php7-zip (7.4.25-r0)
#6 3.863 (25/31) Installing composer (2.1.9-r0)
#6 3.939 (26/31) Installing expat (2.4.1-r0)
#6 3.958 (27/31) Installing git (2.32.0-r0)
#6 4.559 (28/31) Installing openssh-keygen (8.6_p1-r3)
#6 4.589 (29/31) Installing openssh-client-common (8.6_p1-r3)
#6 4.683 (30/31) Installing openssh-client-default (8.6_p1-r3)
#6 4.727 (31/31) Installing patch (2.7.6-r7)
#6 4.749 Executing busybox-1.33.1-r3.trigger
#6 4.754 ERROR: busybox-1.33.1-r3.trigger: script exited with error 1
#6 4.754 Executing ca-certificates-20191127-r5.trigger
#6 4.758 ERROR: ca-certificates-20191127-r5.trigger: script exited with error 1
#6 4.765 1 error; 36 MiB in 45 packages
#6 ERROR: process "/dev/.buildkit_qemu_emulator /bin/sh -c apk update &&     apk add --no-cache composer git bash openssh-client patch &&     apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev" did not complete successfully: exit code: 1
------
 > [2/2] RUN apk update &&     apk add --no-cache composer git bash openssh-client patch &&     apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev:
#6 3.958 (27/31) Installing git (2.32.0-r0)
#6 4.559 (28/31) Installing openssh-keygen (8.6_p1-r3)
#6 4.589 (29/31) Installing openssh-client-common (8.6_p1-r3)
#6 4.683 (30/31) Installing openssh-client-default (8.6_p1-r3)
#6 4.727 (31/31) Installing patch (2.7.6-r7)
#6 4.749 Executing busybox-1.33.1-r3.trigger
#6 4.754 ERROR: busybox-1.33.1-r3.trigger: script exited with error 1
#6 4.754 Executing ca-certificates-20191127-r5.trigger
#6 4.758 ERROR: ca-certificates-20191127-r5.trigger: script exited with error 1
#6 4.765 1 error; 36 MiB in 45 packages
------
Dockerfile.dev:3
--------------------
   2 |     
   3 | >>> RUN apk update && 
   4 | >>>     apk add --no-cache composer git bash openssh-client patch && 
   5 | >>>     apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev
   6 |     
--------------------
error: failed to solve: process "/dev/.buildkit_qemu_emulator /bin/sh -c apk update &&     apk add --no-cache composer git bash openssh-client patch &&     apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev" did not complete successfully: exit code: 1
make: *** [Makefile:18: feature] Error 1
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 2

It’s Gitlab runner version 13.4.1 and Docker executor docker:stable. What can I do about this issue?

Advertisement

Answer

There were three problems with my approach:

  1. I needed to install buildx extension
- mkdir -p ~/.docker/cli-plugins
- wget -qO ~/.docker/cli-plugins/docker-buildx `wget -O - https://api.github.com/repos/docker/buildx/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4`
- chmod a+x ~/.docker/cli-plugins/docker-buildx
  1. I had to install emulators through qemu
- docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  1. I was hosting the Gitlab runner on a CentOS 7 with Kernel 3.13, which is not supported by qemu. After update to Ubuntu 20.04 with Kernel version 5.4 it worked just fine.
3 People found this is helpful
Advertisement