英文:
Gitlab Pipeline with ARM architecture - always fails with: exec /bin/sh: exec format error
问题
只是让你知道,我已经浏览了无数关于这个问题的Stackoverflow问题,并尝试了一切,似乎对我没有用。我尝试过添加shebang,在Dockerfile的FROM中添加了**--platform=linux/arm64**等。
我的问题相当简单。
Dockerfile
FROM node:20.3.0-alpine3.18
RUN apk update
RUN apk add openssl
在我的笔记本上,我为ARM架构服务器构建镜像的方式如下:
docker buildx build -t packagename:latest --platform linux/arm64 .
这完全正常。然而,在Gitlab管道中运行相同的命令时,我收到以下错误:
RUN apk update
exec /bin/sh: exec format error
ERROR: process "/bin/sh -c apk update" did not complete successfully: exit code: 1
在这个工作正常的笔记本上:
- Apple M2 Macbook Air
- Docker版本23.0.5,构建版本bc4487a
Gitlab Runner:
- 基于linux/amd64架构的Ubuntu服务器
- Docker版本23.0.5,构建版本bc4487a
这是我的**.gitlab-ci.yml**文件
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 .
真的需要一些帮助。提前感谢!
英文:
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:
- Apple M2 Macbook Air
- Docker version 23.0.5, build bc4487a
Gitlab Runner:
- Ubuntu Server with linux/amd64 architecture
- Docker version 23.0.5, build bc4487a
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!
答案1
得分: 1
我认为您无法在您的ubuntu linux/amd64
上运行ARM Docker容器,因为它们具有不同的CPU和操作系统架构类型。虽然MacBook可以通过Apple Rosetta 2模拟器/翻译器
来模拟x86架构,但Ubuntu无法默认实现这一点。因此,您需要在AWS/GCP甚至Hetzner Cloud上运行Ubuntu ARM来作为您的GitLab Runner。Buildx只会生成不同架构的构建。详见https://levelup.gitconnected.com/docker-on-apple-silicon-mac-how-to-run-x86-containers-with-rosetta-2-4a679913a0d5
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论