Docker image on an ARM Cortex-A8 32-bit processor

Hi!

I’m trying to build a docker image that runs a script written in C. Everything works fine when I’m running it on my PC (Ubuntu 24 - Intel Core i7).

The problem is when I’m trying to run the docker file on a linux PC (Linux Preemt RT with an ARM cortex A8 32 bit processor).

The Dockerfile below creates a working image. I’m building it with:

sudo docker build -t opc_client .

And running the container with :

sudo docker run -it opc_client

I have tried to change different things on the dockerfile ro get it to work work on the PC that I want to run the container on, but it gives me different kinds of errors. First I tried to change the ‘FROM alpine’ line to ‘FROM arm32v7/alpine’, but that gives me an error on the ‘RUN akg add --no-cache build-base’ line:

=> ERROR [build-env 2/5] RUN apk add --no-cache build-base                1.6s
------                                                                          
 > [build-env 2/5] RUN apk add --no-cache build-base:
1.315 exec /bin/sh: exec format error

I have tried some different solutions when googled around, but I’m pretty stuck here. I guess the problem is to compile the C99 file on an arm32v/alpine image. Some syntax error, or clash with the build-base package.

I appreciate every answer :slight_smile: Thanks in advance.

# use alpine as base image
FROM alpine as build-env
# install build-base meta package inside build-env container
RUN apk add --no-cache build-base
# change directory to /app
WORKDIR /app
# copy all files from current directory inside the build-env container
COPY . .
# Compile the source code and generate hello binary executable file
RUN gcc -std=c99 myclient.c -lm -o opc_client
# use another container to run the program
FROM arm32v7/alpine
# copy binary executable to new container
COPY --from=build-env /app/opc_client /app/opc_client

WORKDIR /app
# at last run the program
CMD ["/app/opc_client"] 

Docker is not a VM or emulator, usually it only runs apps for its own CPU architecture and OS.

Simply using an ARM image on x86 won’t work.

Check doc for multi platform images.

1 Like

Thank you for your answer. I see that I have some reading up to do regarding multi platform images. It wasnt immediately clear to me how the structure of the Dockerfile and build commands should be.

I managed to fix this by using sudo docker buildx build --platform args command.
I pushed this to my dockerhub repo, and then fetched in in the correct platform with the docker pull --platform command. Thank you for your replies!