我在使用 Ubuntu 18.04.01 的开发机器上成功运行了以下 Dockerfile:
FROM arm32v7/openjdk:8-jdk-slim
WORKDIR /app
COPY qemu-arm-static /usr/bin/qemu-arm-static
COPY ./target/edge-0.0.1-SNAPSHOT.jar ./app.jar
COPY ./config/ ./config
RUN groupadd --gid 1337 moduleuser && \
useradd --uid 1337 --gid moduleuser --shell /bin/bash --create-home moduleuser
RUN mkdir -p /var/opt
RUN chown moduleuser:moduleuser -R /var/opt
USER moduleuser
ENTRYPOINT ["java","-jar","./app.jar"]
但是,当我尝试在我们的 CI 环境中构建它时,所有节点都有 16.04,而且我似乎无法在那些环境中运行它。 16.04运行命令输出如下:
$ sudo docker build -f Dockerfile.arm32v7 .
Sending build context to Docker daemon 32.87MB
Step 1/10 : FROM arm32v7/openjdk:8-jdk-slim
---> e5f4973cadb1
Step 2/10 : WORKDIR /app
---> Using cache
---> 44da7413978b
Step 3/10 : COPY qemu-arm-static /usr/bin/qemu-arm-static
---> Using cache
---> ca8c3bde0d92
Step 4/10 : COPY ./target/edge-0.0.1-SNAPSHOT.jar ./app.jar
---> Using cache
---> 90267cfe2fe1
Step 5/10 : COPY ./config/ ./config
---> Using cache
---> 1612aca9fa90
Step 6/10 : RUN groupadd --gid 1337 moduleuser && useradd --uid 1337 --gid moduleuser --shell /bin/bash --create-home moduleuser
---> Running in 7a29d218f15e
standard_init_linux.go:207: exec user process caused "exec format error"
The command '/bin/sh -c groupadd --gid 1337 moduleuser && useradd --uid 1337 --gid moduleuser --shell /bin/bash --create-home moduleuser' returned a non-zero code: 1
作为引用,这里是 18.04 成功构建的输出:
$ docker build -f ./Dockerfile.arm32v7 .
Sending build context to Docker daemon 32.85MB
Step 1/10 : FROM arm32v7/openjdk:8-jdk-slim
---> e5f4973cadb1
Step 2/10 : WORKDIR /app
---> Using cache
---> b8dc45ea966c
Step 3/10 : COPY qemu-arm-static /usr/bin/qemu-arm-static
---> Using cache
---> 43f2b39b8455
Step 4/10 : COPY ./target/edge-0.0.1-SNAPSHOT.jar ./app.jar
---> Using cache
---> bce9640496a9
Step 5/10 : COPY ./config/ ./config
---> Using cache
---> 70c4f5ab3cd1
Step 6/10 : RUN groupadd --gid 1337 moduleuser && useradd --uid 1337 --gid moduleuser --shell /bin/bash --create-home moduleuser
---> Using cache
---> 862b0e48f546
Step 7/10 : RUN mkdir -p /var/opt
---> Using cache
---> 55545e275209
Step 8/10 : RUN chown moduleuser:moduleuser -R /var/opt
---> Using cache
---> 9a5e061b4b84
Step 9/10 : USER moduleuser
---> Using cache
---> 8b049ddef6a6
Step 10/10 : ENTRYPOINT ["java","-jar","./app.jar"]
---> Using cache
---> 433e7e20be3a
Successfully built 433e7e20be3a
如果我在 16.04 机器上使用 arm32v7/openjdk:8-jdk-slim
基于 sudo docker run -it debian:stretch- 的图像启动交互式 session slim
,我可以像这样单独运行命令:
root@557efbe64410:/# groupadd --gid 1337 moduleuser
root@557efbe64410:/# useradd --uid 1337 --gid moduleuser --shell /bin/bash --create-home moduleuser
但是当我运行导致构建错误的命令时,我改为使用 useradd 命令的手册:
两台机器都运行 Docker 版本 18.09.1,build 4c52b90。
我在这里不知所措,我无法弄清楚出了什么问题。任何帮助将不胜感激。
评论中问题的附加信息:
16.04:
$ docker system info --format '{{.Architecture}}'
x86_64
$ uname -m
x86_64
18.04:
$ docker system info --format '{{.Architecture}}'
x86_64
$ uname -m
x86_64
18.04 机器安装了许多其他 qemu 二进制文件。我向他们添加了一个要点 here .然而,我的印象是 qemu-arm-static 可以独立运行并且不依赖于任何其他二进制文件。
我没有使用 binfmt utils,我只是在图像中使用 qemu 模拟 ARM。
最佳答案
事实证明 qemu-arm-static 并不像我最初想象的那样便携。当你安装 qemu-user-static
时,一个映射被添加到内核以使其理解它应该使用 qemu 来解释该体系结构,就像上面的注释一样。我不知道这是幕后发生的事情。
所以有两种方法可以解决这个问题:
sudo apt install qemu-user-static
或
mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register
来源:https://www.balena.io/blog/building-arm-containers-on-any-x86-machine-even-dockerhub/
关于linux - docker build 在 Ubuntu 16.04 上运行命令失败,但在具有相同 Docker 版本的 18.04 上运行命令失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54254109/