嘗試使用 Powershell 和 pip 構建影像,然后運行呼叫內部 python 包的 Powershell 腳本:
> 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"]
我究竟做錯了什么?該腳本直接在我的計算機上運行時運行良好。
uj5u.com熱心網友回復:
您在 Linux 映像中運行它(基于 Ubuntu 20.04 “Focal Fossa”),其中默認 shell 通常是 Bourne shell 的某種風格。您需要以某種方式告訴 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"]
uj5u.com熱心網友回復:
這里有多個答案,但大多數都指的是 x64 架構。請找到鏈接:standard_init_linux.go:178: exec 用戶行程導致“exec 格式錯誤”
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/459785.html
標籤:码头工人 电源外壳 ubuntu 点子 dockerfile
上一篇:為什么`window.matchMedia('(prefers-color-scheme:dark)').matches`在Ubuntu暗模式下回傳`false`
