Just so you know, I have went through countless Stackoverflow questions about this and have tried everything and it seems nothing is working for me. I have tried adding the shebang, added --platform=linux/arm64 in the FROM in the Dockerfile etc.
My issue is rather simple.
Dockerfile
FROM node:20.3.0-alpine3.18
RUN apk update
RUN apk add openssl
On my laptop, I build the image for an ARM architecture server like this:
docker buildx build -t packagename:latest --platform linux/arm64 .
It works just fine. However, when I run the same in the Gitlab pipeline, I get the following error:
RUN apk update
exec /bin/sh: exec format error
ERROR: process "/bin/sh -c apk update" did not complete successfully: exit code: 1
My laptop where this works without any issues:
Gitlab Runner:
Here is my .gitlab-ci.yml file
image: node:20.3.0-alpine3.18
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
stages:
- build
build-container-dev:
stage: build
image: docker:23.0.5
services:
- docker:23.0.5-dind
script:
- docker buildx build -t testrepo:latest --platform linux/arm64 .
Really in need of some help here. Thanks in advance!
I think that you can't run commands in ARM docker containers on your ubuntu linux/amd64
because of different CPU+OS architecture types. While MacBook can emulate x86 architecture for example via Apple Rosetta 2 emulator/translator
- ubuntu can't do this out-of-the-box. So you will need to run Ubuntu ARM on AWS/GCP or even Hetzner Cloud for your GitLab Runner. Buildx just produces builds for a different architecture.
See also https://levelup.gitconnected.com/docker-on-apple-silicon-mac-how-to-run-x86-containers-with-rosetta-2-4a679913a0d5