Search code examples
bashdockerarmqemualpine-linux

Install bash on Alpine/Docker using qemu for ARM host


I am trying to create, at buildtime on an x86 host, a docker container , for runtime on an ARM host. To do this you need to use qemu for cross compilation. I also want to use alpine linux since the image size is so small.

However I am encountering an unusual error that only happens at build time - a problem installing bash.

My understanding is when running apk -U add bash, apk updates the package list from the repositories and then installs the latest version of the package requested. In then runs post-install scripts. It seems these post install scripts fail. However, when I built the image without bash and then ran interactively the container on the ARM host, and did apk fix && apk -U add bash it did the trick. Doing this command at build time fails however.

How can I add bash at buildtime?

Dockerfile

FROM armhf/alpine:3.5

ENV CONSUL_PREFIX __CONSUL_PREFIX__
ENV CONSUL_SECRET_PREFIX __CONSUL_SECRET_PREFIX__

ENV QEMU_EXECVE 1

COPY deploy/qemu/qemu-arm-static            /usr/bin/

RUN ["qemu-arm-static","/sbin/apk","fix"]
RUN ["qemu-arm-static","/sbin/apk","add","-U","bash"]

RUN ["qemu-arm-static","/sbin/apk","-U","add", \
                       "postgresql-client",\
                       "curl","vim",\
                       "tzdata","bc"]

RUN ["qemu-arm-static","/bin/cp","usr/share/zoneinfo/America/Los_Angeles","/etc/localtime"]
RUN ["qemu-arm-static","/bin/echo","America/Los_Angeles",">","/etc/timezone"]
RUN ["qemu-arm-static","/bin/rm","-rf","/var/cache/apk/*"]
RUN ["qemu-arm-static","/bin/sh"]

COPY deploy                         /usr/local/deploy
COPY deploy/default/bashrc          /root/.bashrc
COPY deploy/default/vimrc           /root/.vimrc

COPY src                            /src

Build log / Error

@C02NN3NBG3QT:dev-resources $ ./publish-image
+ : router-logs
+ : quay.io
+ : quay.io/skilbjo/router-logs
+ : skilbjo@github.com
++ echo router-logs
++ tr - _
+ : router_logs/config
++ echo router-logs
++ tr - _
+ : router_logs/secrets
+ cat ../deploy/default/Dockerfile
+ sed 's;__CONSUL_PREFIX__;router_logs/config;'
+ sed 's;__CONSUL_SECRET_PREFIX__;router_logs/secrets;'
+ IMAGE_TAG=dev
+ cd ..
++ git rev-parse HEAD
+ echo 0a865e3918d584b4377fad9afe9ba28a1dbe5968
+ docker build --rm -t quay.io/skilbjo/router-logs:dev .
Sending build context to Docker daemon 8.713 MB
Step 1 : FROM armhf/alpine:3.5
 ---> 3ddfeafc01f0
Step 2 : ENV CONSUL_PREFIX router_logs/config
 ---> Using cache
 ---> e2aae782f6d8
Step 3 : ENV CONSUL_SECRET_PREFIX router_logs/secrets
 ---> Using cache
 ---> 71c863da2558
Step 4 : ENV QEMU_EXECVE 1
 ---> Using cache
 ---> a7e80415d0d4
Step 5 : COPY deploy/qemu/qemu-arm-static /usr/bin/
 ---> Using cache
 ---> 265df9b6575f
Step 6 : RUN qemu-arm-static /sbin/apk fix
 ---> Using cache
 ---> def74ac67891
Step 7 : RUN qemu-arm-static /sbin/apk add -U bash
 ---> Running in 6f62d2ecd6b3
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/armhf/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/armhf/APKINDEX.tar.gz
(1/5) Installing ncurses-terminfo-base (6.0-r7)
(2/5) Installing ncurses-terminfo (6.0-r7)
(3/5) Installing ncurses-libs (6.0-r7)
(4/5) Installing readline (6.3.008-r4)
(5/5) Installing bash (4.3.46-r5)
Executing bash-4.3.46-r5.post-install
ERROR: bash-4.3.46-r5.post-install: script exited with error 1
Executing busybox-1.25.1-r0.trigger
ERROR: busybox-1.25.1-r0.trigger: script exited with error 1
1 errors; 7 MiB in 16 packages
The command 'qemu-arm-static /sbin/apk add -U bash' returned a non-zero code: 1

Project repo is here: https://github.com/skilbjo/router-logs


Solution

  • It turns out FROM armhf/alpine:3.5 is not good and FROM resin/armhf-alpine:3.5 will do the trick! I'd love to be able to see the commants from scratch that resulted in the armhf image being borked, but for now, this works!