简体   繁体   English

docker build 在 Ubuntu 16.04 上运行命令失败,但在 18.04 上使用相同的 Docker 版本失败

[英]docker build fails RUN command at Ubuntu 16.04 but not 18.04 with same Docker verison

I'm running the following Dockerfile successfully on my development machine with Ubuntu 18.04.01:我在使用 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"]

However, when I try to build it in our CI environment, all nodes have 16.04, and I can't seem to run it in those environments.但是,当我尝试在我们的 CI 环境中构建它时,所有节点都有 16.04,而且我似乎无法在这些环境中运行它。 The output of the command run at 16.04 is as follows:在 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

For reference, here is the output from the successful build at 18.04:作为参考,这里是 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

If I start a an interactive session on the 16.04 machine with the image that arm32v7/openjdk:8-jdk-slim is based on using sudo docker run -it debian:stretch-slim , I can succesfully run the commands individually like this:如果我在 16.04 机器上使用arm32v7/openjdk:8-jdk-slim基于的图像启动交互式会话sudo docker run -it debian:stretch-slim arm32v7/openjdk:8-jdk-slim sudo docker run -it debian:stretch-slim ,我可以像这样单独成功地运行命令:

root@557efbe64410:/# groupadd --gid 1337 moduleuser
root@557efbe64410:/# useradd --uid 1337 --gid moduleuser --shell /bin/bash --create-home moduleuser

But when I run the command that causes the error from the build, I instead the manual from the useradd command:但是当我运行导致构建错误的命令时,我改为使用 useradd 命令的手册: 输出

Both machines are running Docker version 18.09.1, build 4c52b90.两台机器都运行 Docker 版本 18.09.1,构建 4c52b90。

I'm at a loss here, I can't figure out what is going wrong.我在这里不知所措,我无法弄清楚出了什么问题。 Any help would be greatly appreciated.任何帮助将不胜感激。

Additional information from questions in comments:评论中问题的其他信息:

16.04: 16.04:

$ docker system info --format '{{.Architecture}}'
x86_64
$ uname -m
x86_64

18.04: 18.04:

$ docker system info --format '{{.Architecture}}'
x86_64
$ uname -m
x86_64

The 18.04 machine has lots of other qemu binaries installed. 18.04 机器安装了许多其他 qemu 二进制文件。 I added a gist with themhere .在这里添加了一个要点。 However, I was under the impression qemu-arm-static could run standalone and didn't depend on any other binaries.但是,我的印象是 qemu-arm-static 可以独立运行并且不依赖于任何其他二进制文件。

I am not using binfmt utils, I am simply emulating ARM using qemu inside the image.我没有使用 binfmt utils,我只是在图像中使用 qemu 模拟 ARM。

It turns out qemu-arm-static is not as portable as I first thought.事实证明 qemu-arm-static 并不像我最初想象的那样便携。 When you install qemu-user-static , a mapping is added to the kernel to make it understand that it should use qemu to interpret that architecture, exactly like a comment said above.当您安装qemu-user-static ,会向内核添加一个映射,以使其理解它应该使用 qemu 来解释该体系结构,就像上面的注释一样。 I didn't know this is what happened under the hood.我不知道这是在幕后发生的事情。

So there are two alternatives to resolve this:所以有两种方法可以解决这个问题:

sudo apt install qemu-user-static

or或者

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  

Source: https://www.balena.io/blog/building-arm-containers-on-any-x86-machine-even-dockerhub/来源: https : //www.balena.io/blog/building-arm-containers-on-any-x86-machine-even-dockerhub/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM