Unable to build docker image, error at RUN apt update

I am running a build with docker build -t .
Building on Ubuntu 20.04 platform target colibri, imx8x, torizon
previously ran correctly ( around 1 year ago last time build performed ) now stopping on errors at RUN command
any help would be appreciated

Output of docker build:

=> ERROR [deploy-container 3/10] RUN apt update 0.2s

[deploy-container 3/10] RUN apt update:
0.239 exec /bin/sh: exec format error


Dockerfile:36

34 | COPY --from=cross-container /project/build/* /usr/local/bin/
35 |
36 | >>> RUN apt update
37 | RUN apt install nano -y
38 | RUN apt install ser2net -y

ERROR: failed to solve: process “/bin/sh -c apt update” did not complete successfully: exit code: 1

ooo

Docker File:

ARG CROSS_TC_IMAGE_ARCH=armhf
ARG CROSS_TC_DOCKER_REGISTRY=torizon
ARG BASE_NAME=debian
ARG IMAGE_ARCH=linux/arm/v7
ARG IMAGE_TAG=2-bullseye
ARG DOCKER_REGISTRY=torizon

First stage, x86_64 build container

FROM $CROSS_TC_DOCKER_REGISTRY/debian-cross-toolchain-$CROSS_TC_IMAGE_ARCH:$IMAGE_TAG AS cross-container
ARG GCC_PREFIX=arm-linux-gnueabihf

install the libpiod development dependencies

RUN apt-get -y update && apt-get -y upgrade && apt-get install -y
libgpiod-dev:$CROSS_TC_IMAGE_ARCH
libgpiod2:$CROSS_TC_IMAGE_ARCH
nano:$CROSS_TC_IMAGE_ARCH \
&& apt-get clean && apt-get autoremove && rm -rf /var/lib/apt/lists/*

copy project source

WORKDIR /project
COPY src/ /project
COPY ser2net.conf /project

compile

RUN mkdir build && cd build
&& $GCC_PREFIX-gcc -Wall -g -D_GNU_SOURCE -o qse
…/iio_utils.c …/main.c …/serCmd.c …/adc_utils.c …/pwm_utils.c

Second stage, container for target

FROM --platform=$IMAGE_ARCH $DOCKER_REGISTRY/$BASE_NAME:$IMAGE_TAG AS deploy-container

get the compiled program from the Build stage

COPY --from=cross-container /project/build/* /usr/local/bin/

RUN apt update <<<<<<<< Fails at this point with message above

Hey @RayO, thanks for reaching out!

Short answer: do this Configure Build Environment for Torizon Containers | Toradex Developer Center. You may also need to apt-get install qemu-arm-static.

Long answer: exec /bin/sh: exec format error happens when you don’t have binfmt_misc enabled in your Linux system, which is a kernel capability that makes it possible to execute binary files from a foreign architecture (in this case arm) from - in this case - x86 native machine. The steps above will basically tell your Linux something along the lines of “if you detect I’m trying to run an arm binary, please run it using QEMU instead of trying to natively execute it”.

Hope that helps!

Thank you very much Leon,
Your reference lead me to perform the following steps which allowed my docker build to complete by installing some needed modules.
Best Regards,
Ray

docker run --rm -it --privileged torizon/binfmt
docker run --rm -it arm32v7/debian arch
verifying with:
docker run --rm --platform linux/arm/v7 -it arm32v7/debian arch
which returns the following when arm/v7 cross environment is ok:
armv7l

1 Like