Home > Enterprise >  Pip and Powershell inside Docker: standard_init_linux.go:228: exec user process caused: exec format
Pip and Powershell inside Docker: standard_init_linux.go:228: exec user process caused: exec format

Time:04-19

Trying to build an image with Powershell and pip and then run a Powershell script which calls a python package inside:

> 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

But getting the following error:

> docker run -it --rm --name psutest psu
standard_init_linux.go:228: exec user process caused: exec format error

My 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"]

What am I doing wrong? The script runs just fine when run directly on my computer.

CodePudding user response:

There are multiple answers here, but most of them referring to x64 architecture. Please find the link: standard_init_linux.go:178: exec user process caused "exec format error"

CodePudding user response:

You're running this inside a Linux image (based on Ubuntu 20.04 "Focal Fossa"), where the default shell will generally be some flavor of the Bourne shell. You need to tell Linux somehow that it needs to use Powershell to run the script.

The best way to do this is to begin the script with a "shebang" line. This will look roughly like

#!/usr/bin/pwsh -File

Whenever the script is marked executable (chmod x gallery-dl.ps1), Linux (and any other Unix) will find the shebang line and run that command, passing the script name and any additional parameters to it. This must begin at the absolute very first byte of the file – no comments or newlines or anything else before it – and this is a place where DOS line endings will cause problems. Since this line is also a Powershell comment, it will have no effect on the script when it runs.

You can also put the interpreter in the Docker image's command. This on some level is repeating yourself, and if you need to run an alternate script as the main container process sometimes, you'll have to repeat the pwsh interpreter for every alternate script.

# instead of the ENTRYPOINT line you currently have
CMD ["/usr/bin/pwsh", "-File", "/mydir/gallery-dl.ps1"]
  • Related