【问题标题】:Docker : exec /usr/bin/sh: exec format errorDocker : exec /usr/bin/sh: exec 格式错误
【发布时间】:2022-11-03 08:01:11
【问题描述】:

嗨,伙计们需要一些帮助。

我创建了一个自定义 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

.gitlab-ci.yml

robot-framework:
  image: rethkevin/rf:v1
  allow_failure: true
  script:
    - ls
    - pip3 --version

输出

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

有什么想法可以解决这个错误吗?

【问题讨论】:

  • 你能提供完整的作业日志输出吗?
  • 该错误意味着错误的架构,例如试图在 x86-64 系统上运行的 arm64 代码。

标签: python docker gitlab robotframework dockerhub


【解决方案1】:

问题是你为 arm64/v8 构建了这个镜像——但是你的跑步者使用了不同的架构。

如果你运行:

docker image inspect rethkevin/rf:v1

您将在输出中看到:

...
        "Architecture": "arm64",
        "Variant": "v8",
        "Os": "linux",
...

尝试从 GitLab CI 运行器构建和推送图像,以便图像的架构与运行器的架构相匹配。

或者,您可以 build for multiple architectures 使用 docker buildx 。或者,您也可以在 ARM 架构上运行 GitLab 运行程序,以便它可以运行您构建它的架构的映像。

【讨论】:

  • 对不起,我是新手,会试试这个。我如何检查跑步者的架构?
  • @rkevx21 几乎可以肯定是 amd64 (x86_64) -- 在 Linux 系统上,您可以运行 uname -muname -a 进行检查。最简单的做法是使用您的跑步者构建和推送您的图像,以便图像与它发生的任何内容相匹配。
  • 你说的对。我在 Mac M1 上构建图像。于是就遇到了这个问题。
【解决方案2】:

就我而言,我使用 buildx 构建它

docker buildx build --platform linux/amd64 -f ./Dockerfile -t image .

但是问题出在 AWS lambda

【讨论】:

    猜你喜欢
    • 2022-12-30
    • 2022-07-09
    • 2022-08-18
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    • 2018-06-06
    • 1970-01-01
    相关资源
    最近更新 更多