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 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"]