在 Windows 10 上构建 Linux Docker 图像:"exec format error"
Building a Linux Docker image on Windows 10: "exec format error"
我用的是底图,如下图:https://github.com/Kaggle/docker-python/blob/main/Dockerfile.
这是我的 Dockerfile:
FROM kaggle/python
RUN ["chmod", "+x", "/opt/conda/etc/profile.d/conda.sh"]
SHELL ["/bin/bash", "--login", "-c" ]
RUN ["/opt/conda/etc/profile.d/conda.sh"]
ENTRYPOINT [ "/usr/bin/env" ]
RUN ["exec '$@'"]
RUN ["bash"]
我是运行命令:docker build -t kaggle/no-jupyter .
在第 4 行我得到错误:
> [3/7] RUN ["/opt/conda/etc/profile.d/conda.sh"]:
#6 0.263 standard_init_linux.go:228: exec user process caused: exec format error
这是 conda.sh 文件的 link:https://pastebin.com/Epu4d7Nq
我读到这可能是因为我正在 Windows10 上构建一个 Linux 图像...有什么想法吗?
RUN
RUN has 2 forms:
RUN (shell form, the command is run in a shell, which by default is /bin/sh -c on Linux or cmd /S /C on Windows)
RUN ["executable", "param1", "param2"] (exec form)
你选择的是 exec form
而不会 运行 在 shell 中,所以你的 /opt/conda/etc/profile.d/conda.sh
肯定会失败。
要修复它,您需要更改为:
RUN ["bash", "/opt/conda/etc/profile.d/conda.sh"]
或者直接使用shell form
:
RUN /opt/conda/etc/profile.d/conda.sh
最小示例:
run.sh:
echo "hello"
Dockerfile:
FROM ubuntu:16.04
COPY run.sh /
RUN ["bash", "/run.sh"]
执行:
$ docker build -t abc:1 . --no-cache
Sending build context to Docker daemon 3.072kB
Step 1/3 : FROM ubuntu:16.04
---> 065cf14a189c
Step 2/3 : COPY run.sh /
---> 8741ec438afd
Step 3/3 : RUN ["bash", "/run.sh"]
---> Running in 5e6754c79bc1
hello
Removing intermediate container 5e6754c79bc1
---> 3edd77959de4
Successfully built 3edd77959de4
Successfully tagged abc:1
AND,如果不使用bash
,会出现如下错误:
Dockerfile:
FROM ubuntu:16.04
COPY run.sh /
RUN ["/run.sh"]
执行:
$ docker build -t abc:1 . --no-cache
Sending build context to Docker daemon 3.072kB
Step 1/3 : FROM ubuntu:16.04
---> 065cf14a189c
Step 2/3 : COPY run.sh /
---> 82412a703847
Step 3/3 : RUN ["/run.sh"]
---> Running in 2a2b00f966c7
standard_init_linux.go:211: exec user process caused "exec format error"
The command '/run.sh' returned a non-zero code: 1
我用的是底图,如下图:https://github.com/Kaggle/docker-python/blob/main/Dockerfile.
这是我的 Dockerfile:
FROM kaggle/python
RUN ["chmod", "+x", "/opt/conda/etc/profile.d/conda.sh"]
SHELL ["/bin/bash", "--login", "-c" ]
RUN ["/opt/conda/etc/profile.d/conda.sh"]
ENTRYPOINT [ "/usr/bin/env" ]
RUN ["exec '$@'"]
RUN ["bash"]
我是运行命令:docker build -t kaggle/no-jupyter .
在第 4 行我得到错误:
> [3/7] RUN ["/opt/conda/etc/profile.d/conda.sh"]:
#6 0.263 standard_init_linux.go:228: exec user process caused: exec format error
这是 conda.sh 文件的 link:https://pastebin.com/Epu4d7Nq
我读到这可能是因为我正在 Windows10 上构建一个 Linux 图像...有什么想法吗?
RUN
RUN has 2 forms:
RUN (shell form, the command is run in a shell, which by default is /bin/sh -c on Linux or cmd /S /C on Windows)
RUN ["executable", "param1", "param2"] (exec form)
你选择的是 exec form
而不会 运行 在 shell 中,所以你的 /opt/conda/etc/profile.d/conda.sh
肯定会失败。
要修复它,您需要更改为:
RUN ["bash", "/opt/conda/etc/profile.d/conda.sh"]
或者直接使用shell form
:
RUN /opt/conda/etc/profile.d/conda.sh
最小示例:
run.sh:
echo "hello"
Dockerfile:
FROM ubuntu:16.04
COPY run.sh /
RUN ["bash", "/run.sh"]
执行:
$ docker build -t abc:1 . --no-cache
Sending build context to Docker daemon 3.072kB
Step 1/3 : FROM ubuntu:16.04
---> 065cf14a189c
Step 2/3 : COPY run.sh /
---> 8741ec438afd
Step 3/3 : RUN ["bash", "/run.sh"]
---> Running in 5e6754c79bc1
hello
Removing intermediate container 5e6754c79bc1
---> 3edd77959de4
Successfully built 3edd77959de4
Successfully tagged abc:1
AND,如果不使用bash
,会出现如下错误:
Dockerfile:
FROM ubuntu:16.04
COPY run.sh /
RUN ["/run.sh"]
执行:
$ docker build -t abc:1 . --no-cache
Sending build context to Docker daemon 3.072kB
Step 1/3 : FROM ubuntu:16.04
---> 065cf14a189c
Step 2/3 : COPY run.sh /
---> 82412a703847
Step 3/3 : RUN ["/run.sh"]
---> Running in 2a2b00f966c7
standard_init_linux.go:211: exec user process caused "exec format error"
The command '/run.sh' returned a non-zero code: 1