Hi guys need some help.
I created a custom docker image and push it to docker hub but when I run it in CI/CD it gives me this error.
exec /usr/bin/sh: exec format error
Where :
Dockerfile
FROM ubuntu:20.04
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN apt-get install -y python3-pip
RUN pip3 install robotframework
.gitlab-ci.yml
robot-framework:
image: rethkevin/rf:v1
allow_failure: true
script:
- ls
- pip3 --version
Output
Running with gitlab-runner 15.1.0 (76984217)
on runner zgjy8gPC
Preparing the "docker" executor
Using Docker executor with image rethkevin/rf:v1 ...
Pulling docker image rethkevin/rf:v1 ...
Using docker image sha256:d2db066f04bd0c04f69db1622cd73b2fc2e78a5d95a68445618fe54b87f1d31f for rethkevin/rf:v1 with digest rethkevin/rf@sha256:58a500afcbd75ba477aa3076955967cebf66e2f69d4a5c1cca23d69f6775bf6a ...
Preparing environment
00:01
Running on runner-zgjy8gpc-project-1049-concurrent-0 via 1c8189df1d47...
Getting source from Git repository
00:01
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in /builds/reth.bagares/test-rf/.git/
Checking out 339458a3 as main...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:00
Using docker image sha256:d2db066f04bd0c04f69db1622cd73b2fc2e78a5d95a68445618fe54b87f1d31f for rethkevin/rf:v1 with digest rethkevin/rf@sha256:58a500afcbd75ba477aa3076955967cebf66e2f69d4a5c1cca23d69f6775bf6a ...
exec /usr/bin/sh: exec format error
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
any thoughts on this to resolve the error?
5
Answers
The problem is that you built this image for arm64/v8 — but your runner is using a different architecture.
If you run:
You will see this in the output:
Try building and pushing your image from your GitLab CI runner so the architecture of the image will match your runner’s architecture.
Alternatively, you can build for multiple architectures using
docker buildx
. Alternatively still, you could also run a GitLab runner on ARM architecture so that it can run the image for the architecture you built it on.In my case, I was building it using buildx
however the problem was in AWS lambda
You should also be sure that what you’re calling is indeed an executable. We made this mistake:
And the error was:
The OS was not able to execute a txt file and threw a architecture-like error.
There could be many reasons why this error occurs while working with containers:
Demonestrate here the reason (3) with example:
rohits-MacBook> catalog % docker version
Its darwin/arm64 architectute of my Laptop and the same docker Engine is installed.
#################################################
Executing in my current laptop
rohits-MacBook> catalog % make image
##############################
rohits-MacBook> catalog % docker images
######################################
rohits-MacBook> osscatalog % docker image inspect api-catalog
Produces an
arm64
image########################################
Issue after running instance in its log file shows:
rohits-MacBook> api-osscatalog % kubectl -n api logs -f catimporter-rohit-gst45
Comment:
This usually happens when you’re working on projects on a system with ARM architecture, like with the new Apple M-series chipsets. When you push a code to your production environment, which is using an x86 system, it results in the “exec user process caused: exec format error”. This is because every piece of code when converted to the lower level of instructions is different for both ARM and x86. Docker detects the Apple M1 Pro platform as “linux/arm64/v8“.
################## SOLUTION ########################
1.
/cloud-sre/catalog/Makefile
Change:
docker build -t $(IMAGE_NAME):latest .
To:
docker buildx build --platform=linux/amd64 -t $(IMAGE_NAME):latest .
/cloud-sre/catalog/Dockerfile
Change:
FROM docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7
To:
FROM --platform=linux/amd64 docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7
#################### TEST ######################
rohits-MacBook> catalog % docker images
Deleted all image
#####################################
rohits-MacBook> catalog %
rohits-MacBook> catalog % make image
##############################################
rohits-MacBook> catalog % docker images
################################################
rohits-MacBook> catalog % docker image inspect api-catalog:latest
— Which I used to get in my old laptop always.
############################################
Now checking the log from the new instance:
rohits-MacBook> api-ocatalog % kubectl -n api logs -f catimporter-rohit-9bzk9
No Error
For developers having similar error on AWS codebuild –
I had this error when using AWS codebuild, the issue persists when you use different arch on the build stage and deploy stage. My build stage was building docker images on arm64 arch and deploying them on EC2 which was on _8664 arch. Changing the build arch to _8664 fixed the problem