尝试用Powershell和pip构建一个映像,然后运行一个Powershell脚本,它在里面调用python包:
> docker build --file gallery-dl.dockerfile --tag psu .
[+] Building 0.6s (9/9) FINISHED
=> [internal] load build definition from gallery-dl.dockerfile 0.0s
=> => transferring dockerfile: 413B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for mcr.microsoft.com/powershell:7.3.0-preview.3-ubunt 0.2s
=> [internal] load build context 0.0s
=> => transferring context: 36B 0.0s
=> [1/4] FROM mcr.microsoft.com/powershell:7.3.0-preview.3-ubuntu-focal-20220318@s 0.0s
=> CACHED [2/4] RUN apt-get update && apt-get -qq -y install curl ca-certifica 0.0s
=> CACHED [3/4] RUN pip3 install https://github.com/mikf/gallery-dl/archive/master 0.0s
=> [4/4] COPY gallery-dl.ps1 /mydir/ 0.1s
=> exporting to image 0.1s
=> => exporting layers 0.1s
=> => writing image sha256:6bd7be9979190bf2993e5473265284883b0c154c1e62f5bb27d74c0 0.0s
=> => naming to docker.io/library/psu 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
但是得到以下错误:
> docker run -it --rm --name psutest psu
standard_init_linux.go:228: exec user process caused: exec format error
我的Dockerfile:
FROM mcr.microsoft.com/powershell:7.3.0-preview.3-ubuntu-focal-20220318
RUN apt-get update && \
apt-get -qq -y install curl ca-certificates python3-pip
RUN pip3 install https://github.com/mikf/gallery-dl/archive/master.zip https://github.com/yt-dlp/yt-dlp/archive/master.zip
COPY gallery-dl.ps1 /mydir/
ENTRYPOINT ["/mydir/gallery-dl.ps1"]
我做错了什么?当直接在我的计算机上运行时,脚本运行得很好。
发布于 2022-04-18 23:45:16
您在Linux映像(基于Ubuntu20.04“焦Fossa")中运行这个程序,默认的shell通常是Bourne的一些味道。您需要告诉Linux,它需要使用Powershell来运行脚本。
这样做的最好方法是以"shebang“行开始脚本。这看起来很像
#!/usr/bin/pwsh -File
每当脚本被标记为可执行文件(chmod +x gallery-dl.ps1
)时,Linux (和任何其他Unix)都会找到shebang行并运行该命令,将脚本名和任何附加参数传递给它。这必须从文件的绝对第一个字节开始--没有注释、换行符或它之前的任何东西--这是DOS行结尾会引起问题的地方。因为这行也是一个Powershell注释,所以它在运行时不会对脚本产生任何影响。
您还可以将解释器放在Docker映像的命令中。在某种程度上,这是在重复自己,如果有时需要将备用脚本作为主容器进程运行,则必须对每个备用脚本重复使用pwsh
解释器。
# instead of the ENTRYPOINT line you currently have
CMD ["/usr/bin/pwsh", "-File", "/mydir/gallery-dl.ps1"]
发布于 2022-04-18 06:20:35
这里有多种答案,但大多数答案都涉及到x64体系结构。请找到链接:standard_init_linux.go:178: exec user process caused "exec format error"
https://stackoverflow.com/questions/71907799
复制相似问题