rke*_*x21 109 gitlab docker gitlab-ci dockerhub gitlab-ci-runner
我创建了一个自定义 docker 映像并将其推送到 docker hub,但是当我在 CI/CD 中运行它时,它给了我这个错误。
exec /usr/bin/sh: exec format error
在哪里 :
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
Run Code Online (Sandbox Code Playgroud)
.gitlab-ci.yml
robot-framework:
image: rethkevin/rf:v1
allow_failure: true
script:
- ls
- pip3 --version
Run Code Online (Sandbox Code Playgroud)
输出
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
Run Code Online (Sandbox Code Playgroud)
对此有什么想法可以解决该错误吗?
syt*_*ech 136
问题是您为 arm64/v8 构建了此映像 - 但您的运行程序使用了不同的架构。
如果你运行:
docker image inspect rethkevin/rf:v1
Run Code Online (Sandbox Code Playgroud)
您将在输出中看到这一点:
...
"Architecture": "arm64",
"Variant": "v8",
"Os": "linux",
...
Run Code Online (Sandbox Code Playgroud)
尝试从 GitLab CI 运行程序构建和推送映像,以便映像的架构与您的运行程序的架构相匹配。
或者,您可以使用docker buildx
. 或者,您也可以在 ARM 架构上运行 GitLab 运行程序,以便它可以运行您构建的架构的映像。
使用现代版本的 docker,您还可以显式控制 docker 使用的平台。如果指定的平台与您的本机平台不同,Docker 将使用平台模拟。
例如:
使用DOCKER_DEFAULT_PLATFORM
环境变量:
docker image inspect rethkevin/rf:v1
Run Code Online (Sandbox Code Playgroud)
--platform
在 CLI 或 dockerfile 中使用参数:
...
"Architecture": "arm64",
"Variant": "v8",
"Os": "linux",
...
Run Code Online (Sandbox Code Playgroud)
FROM --platform=linux/amd64 ubuntu:jammy
Run Code Online (Sandbox Code Playgroud)
安装了 docker 桌面的系统应该已经能够做到这一点。如果您的系统使用没有 docker 桌面的 docker,则可能需要显式安装 docker-buildx 插件。
MMS*_*MSA 46
就我而言,我使用 buildx 构建它
docker buildx build --platform linux/amd64 -f ./Dockerfile -t image .
Run Code Online (Sandbox Code Playgroud)
Roh*_*asu 13
使用容器时发生此错误的原因可能有很多:
\n这里举例说明原因(3):
\nrohits-MacBook>目录%docker版本
\n我的笔记本电脑的 darwin/arm64 架构和相同的 docker 引擎已安装。
\nClient:\n Cloud integration: v1.0.31\n Version: 20.10.23\n API version: 1.41\n Go version: go1.18.10\n Git commit: 7155243\n Built: Thu Jan 19 17:35:19 2023\n OS/Arch: darwin/arm64\n Context: desktop-linux\n Experimental: true\n\nServer: Docker Desktop 4.17.0 (99724)\n Engine:\n Version: 20.10.23\n API version: 1.41 (minimum version 1.12)\n Go version: go1.18.10\n Git commit: 6051f14\n Built: Thu Jan 19 17:31:28 2023\n OS/Arch: linux/arm64\n Experimental: false\n containerd:\n Version: 1.6.18\n GitCommit: 2456e983eb9e37e47538f59ea18f2043c9a73640\n runc:\n Version: 1.1.4\n GitCommit: v1.1.4-0-g5fd4c4d\n docker-init:\n Version: 0.19.0\n GitCommit: de40ad0\n
Run Code Online (Sandbox Code Playgroud)\n##################################################
\n在我当前的笔记本电脑上执行
\nrohits-MacBook>目录%制作图像
\nCGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-X github.ibm.com/cloud-sre/version.Major= -X github.ibm.com/cloud-sre/version.Minor= -X github.ibm.com/cloud-sre/version.Build= -X github.ibm.com/cloud-sre/version.Timestamp=202303170049" -o osscatimporter ./cmd/osscatimporter\nCGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-X github.ibm.com/cloud-sre/version.Major= -X github.ibm.com/cloud-sre/version.Minor= -X github.ibm.com/cloud-sre/version.Build= -X github.ibm.com/cloud-sre/version.Timestamp=202303170049" -o osscatpublisher ./cmd/osscatpublisher\njq: error: Could not open file metadata.json: No such file or directory\ndocker buildx build --platform=linux/amd64 -t api-osscatalog:latest .\n[+] Building 153.2s (11/11) FINISHED \n => [internal] load build definition from Dockerfile 0.0s\n => => transferring dockerfile: 560B 0.0s\n => [internal] load .dockerignore 0.0s\n => => transferring context: 2B 0.0s\n => [internal] load metadata for docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7 34.2s\n => [auth] ubi8/ubi-minimal:pull token for docker-virtual.artifactory.swg-devops.com 0.0s\n => [1/5] FROM docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7@sha256:65a240ad8bd3f2fff3e18a22ebadc40da0b145616231fc1e1625 91.3s\n => => resolve docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7@sha256:65a240ad8bd3f2fff3e18a22ebadc40da0b145616231fc1e16251 0.0s\n => => sha256:0214a28336e387c66493c61bb394e86a18f3bea8dbc46de74a26f173ff553c89 429B / 429B 0.0s\n => => sha256:591670a5d6a620931ec51c1e7436300894f5320e76e9737f0366fc62114addd4 6.23kB / 6.23kB 0.0s\n => => sha256:d7c06497d5cebd39c0a4feb14981ec940b5c863e49903d320f630805b049cbff 39.28MB / 39.28MB 90.8s\n => => sha256:65a240ad8bd3f2fff3e18a22ebadc40da0b145616231fc1e16251f3c6dee087a 1.47kB / 1.47kB 0.0s\n => => extracting sha256:d7c06497d5cebd39c0a4feb14981ec940b5c863e49903d320f630805b049cbff 0.4s\n => [internal] load build context 0.2s\n => => transferring context: 23.77MB 0.2s\n => [2/5] RUN microdnf update && microdnf install procps ; 27.5s\n => [3/5] COPY osscatimporter / 0.0s\n => [4/5] COPY mailtemplate.tmpl / 0.0s\n => [5/5] COPY osscatpublisher / 0.0s \n => exporting to image 0.1s \n => => exporting layers 0.1s \n => => writing image sha256:8af2a24809c709c2ea80b1f3ed0c0d1dc1381c84219e0e779be43ab8542e8c0d 0.0s \n => => naming to docker.io/library/api-osscatalog:latest 0.0s\n
Run Code Online (Sandbox Code Playgroud)\n################################
\nrohits-MacBook> 目录 % docker 镜像
\nREPOSITORY TAG IMAGE ID CREATED SIZE\napi-catalog latest 8af2a24809c7 9 seconds ago 140MB\n
Run Code Online (Sandbox Code Playgroud)\n########################################
\nrohits-MacBook> osscatalog % docker 镜像检查 api-catalog
\n\n "Architecture": "arm64",\n "Os": "linux",\n "Size": 148693891,\n "VirtualSize": 148693891,\n
Run Code Online (Sandbox Code Playgroud)\n产生 arm64
图像
##########################################
\nrohits-MacBook> api-osscatalog % kubectl -n api 日志 -f catimporter-rohit-gst45
\nexec /bin/sh: exec format error\nrohits-MacBook> api-catalog % \n
Run Code Online (Sandbox Code Playgroud)\n当您\xe2\x80\x99 在采用 ARM 架构的系统(例如新的\xc2\xa0Apple M 系列芯片组)上处理项目时,通常会发生这种情况。当您将代码推送到使用 x86 系统的生产环境时,会导致 \xe2\x80\x9cexec 用户进程导致:exec format error\xe2\x80\x9d。这是因为对于 ARM 和 x86,转换为较低级别指令时的每段代码都是不同的。Docker 将 Apple M1 Pro 平台检测为 \xe2\x80\x9clinux/arm64/v8\xe2\x80\x9c。
\n################## 解决方案 ########################
\n1.\n /cloud-sre/catalog/Makefile
\n更改:\n docker build -t $(IMAGE_NAME):latest .
\n至:\ndocker buildx build --platform=linux/amd64 -t $(IMAGE_NAME):latest .
/cloud-sre/catalog/Dockerfile
\n更改:\n FROM docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7
\n到:\nFROM --platform=linux/amd64 docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7
#################### 测试 ######################
\nrohits-MacBook> 目录 % docker 镜像
\nREPOSITORY TAG IMAGE ID CREATED SIZE\n
Run Code Online (Sandbox Code Playgroud)\n删除了所有图像
\n######################################
\nrohits-MacBook> 目录 %\nrohits-MacBook> 目录 % 制作映像
\nCGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-X github.ibm.com/cloud-sre/version.Major= -X github.ibm.com/cloud-sre/version.Minor= -X github.ibm.com/cloud-sre/version.Build= -X github.ibm.com/cloud-sre/version.Timestamp=202303170049" -o osscatimporter ./cmd/osscatimporter\nCGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-X github.ibm.com/cloud-sre/version.Major= -X github.ibm.com/cloud-sre/version.Minor= -X github.ibm.com/cloud-sre/version.Build= -X github.ibm.com/cloud-sre/version.Timestamp=202303170049" -o osscatpublisher ./cmd/osscatpublisher\njq: error: Could not open file metadata.json: No such file or directory\ndocker buildx build --platform=linux/amd64 -t api-osscatalog:latest .\n[+] Building 153.2s (11/11) FINISHED \n => [internal] load build definition from Dockerfile 0.0s\n => => transferring dockerfile: 560B 0.0s\n => [internal] load .dockerignore 0.0s\n => => transferring context: 2B 0.0s\n => [internal] load metadata for docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7 34.2s\n => [auth] ubi8/ubi-minimal:pull token for docker-virtual.artifactory.swg-devops.com 0.0s\n => [1/5] FROM docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7@sha256:65a240ad8bd3f2fff3e18a22ebadc40da0b145616231fc1e1625 91.3s\n => => resolve docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7@sha256:65a240ad8bd3f2fff3e18a22ebadc40da0b145616231fc1e16251 0.0s\n => => sha256:0214a28336e387c66493c61bb394e86a18f3bea8dbc46de74a26f173ff553c89 429B / 429B 0.0s\n => => sha256:591670a5d6a620931ec51c1e7436300894f5320e76e9737f0366fc62114addd4 6.23kB / 6.23kB 0.0s\n => => sha256:d7c06497d5cebd39c0a4feb14981ec940b5c863e49903d320f630805b049cbff 39.28MB / 39.28MB 90.8s\n => => sha256:65a240ad8bd3f2fff3e18a22ebadc40da0b145616231fc1e16251f3c6dee087a 1.47kB / 1.47kB 0.0s\n => => extracting sha256:d7c06497d5cebd39c0a4feb14981ec940b5c863e49903d320f630805b049cbff 0.4s\n => [internal] load build context 0.2s\n => => transferring context: 23.77MB 0.2s\n => [2/5] RUN microdnf update && microdnf install procps ; 27.5s\n => [3/5] COPY osscatimporter / 0.0s\n => [4/5] COPY mailtemplate.tmpl / 0.0s\n => [5/5] COPY osscatpublisher / 0.0s \n => exporting to image 0.1s \n => => exporting layers 0.1s \n => => writing image sha256:8af2a24809c709c2ea80b1f3ed0c0d1dc1381c84219e0e779be43ab8542e8c0d 0.0s \n => => naming to docker.io/library/api-osscatalog:latest 0.0s\n
Run Code Online (Sandbox Code Playgroud)\n################################################
\nrohits-MacBook> 目录 % docker 镜像
\nREPOSITORY TAG IMAGE ID CREATED SIZE\napi-catalog latest 8af2a24809c7 9 seconds ago 140MB\n
Run Code Online (Sandbox Code Playgroud)\n##################################################\nrohits -MacBook>目录%docker镜像检查api-catalog:最新
\n\n "Architecture": "amd64",\n "Os": "linux",\n "Size": 140425582,\n
Run Code Online (Sandbox Code Playgroud)\n\xe2\x80\x94 我以前总是在我的旧笔记本电脑中找到它。
\n##############################################
\n现在检查新实例的日志:
\nrohits-MacBook> api-ocatalog % kubectl -n api 日志 -f catimporter-rohit-9bzk9
\nINFO 19:53:29 osscatimporter Version: .. - 202303170049\nINFO 19:53:29 sending *osscatimporter* Starting Run osscatimporter using the slack-webhook-url Slack webhook key.\nTest COS connection passed: oss-rmc-data-test\nTest COS connection passed: oss-rmc-emergency-test\nAUDIT 19:53:30 Operating in read-only mode on all services and components found from all sources (with visibility=private and above)\nINFO 19:53:30 Forcing -check-owner=true\nINFO 19:53:30 Optional run action ENABLED: Services\nINFO 19:53:30 Optional run action ENABLED: Tribes\nINFO 19:53:30 Optional run action ENABLED: Environments\nINFO 19:53:30 Optional run action ENABLED: Deployments\nINFO 19:53:30 Optional run action ENABLED: Monitoring\nINFO 19:53:30 Optional run action ENABLED: RMC\nINFO 19:53:30 Optional run action ENABLED: RMC-Rescan\nINFO 19:53:30 Optional run action DISABLED: Environments-Native\nINFO 19:53:30 Optional run action DISABLED: ProductInfo-Parts\nINFO 19:53:30 Optional run action DISABLED: ProductInfo-Parts-Refresh\nINFO 19:53:30 Optional run action DISABLED: ProductInfo-ClearingHouse\nINFO 19:53:30 Optional run action DISABLED: Dependencies-ClearingHouse\nINFO 19:53:30 Optional run action DISABLED: ScorecardV1\nINFO 19:53:30 Optional run action DISABLED: Doctor\nINFO 19:53:30 Skip reloading Segment and Tribe Info from ScorecardV1\n
Run Code Online (Sandbox Code Playgroud)\n没有错误
\n小智 6
对于在 AWS codebuild 上遇到类似错误的开发人员 - 我在使用 AWS codebuild 时遇到了此错误,当您在构建阶段和部署阶段使用不同的架构时,问题仍然存在。我的构建阶段是在arm64 arch上构建docker镜像并将它们部署在_86*64
arch上的EC2上。更改构建拱门以_86*64
解决问题
小智 5
我收到此错误是因为我试图执行顶部没有 shebang 行的 Bash 脚本。
我通过在文件顶部添加 shebang 行解决了这个问题:
#!/bin/bash
...
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
186263 次 |
最近记录: |