I've been able to find the root cause: The error message means that Gradle cannot connect to some worker processes. In my case, the process was for 'aapt2'. Running 'ldd aapt2' indicated that some shared libraries were missing (mainly GLIBC). Since I'm using Docker based on Alpine Linux, it comes with a reduced GLIBC (glibc-musl). The solution was to simply install glibc.
Here is the complete Dockerfile for reference, although the missing libraries might be different for your distribution.
FROM openjdk:8-alpine
LABEL maintainer="Barry Lagerweij" \
maintainer.email="b.lagerweij@carepay.co.ke" \
description="Android Builder"
COPY android-packages /tmp/android-packages
RUN apk add --no-cache wget unzip ca-certificates \
&& wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub \
&& wget -q -O /tmp/glibc.apk https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.26-r0/glibc-2.26-r0.apk \
&& wget -q -O /tmp/glibc-bin.apk https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.26-r0/glibc-bin-2.26-r0.apk \
&& apk add --no-cache /tmp/glibc.apk /tmp/glibc-bin.apk \
&& wget -q -O /tmp/android-tools.zip https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip \
&& mkdir -p /tmp/android-sdk/licenses \
&& unzip /tmp/android-tools.zip -d /tmp/android-sdk \
&& rm /tmp/android-tools.zip \
&& echo "d56f5187479451eabf01fb78af6dfcb131a6481e" > /tmp/android-sdk/licenses/android-sdk-license \
&& echo "84831b9409646a918e30573bab4c9c91346d8abd" > /tmp/android-sdk/licenses/android-sdk-preview-license \
&& echo "d975f751698a77b662f1254ddbeed3901e976f5a" > /tmp/android-sdk/licenses/intel-android-extra-license \
&& mkdir ~/.android; echo "count=0" >> ~/.android/repositories.cfg \
&& /tmp/android-sdk/tools/bin/sdkmanager --package_file=/tmp/android-packages \
&& apk del wget unzip ca-certificates \
&& rm -rf /tmp/android-sdk/extras /tmp/android-sdk/tools/lib/x86 /tmp/android-sdk/tools/lib/monitor-* /tmp/glibc.apk /tmp/glibc-bin.apk /etc/apk/keys/sgerrand.rsa.pub
RUN mkdir /tmp/project \
&& echo "sdk.dir=/tmp/android-sdk" > /tmp/project/local.properties
ENV ANDROID_HOME /tmp/android-sdk
WORKDIR /tmp/project
I suggest you run 'ldd build-tools/26.0.2/aapt2' to see which libraries are missing from the OS.