Docker Community Forums

Share and learn in the Docker community.

How i can run python script from Docker container

I am newbie to Docker and trying to run python script in Docker container.

My docker file:


Let us use PowerShell line continuation.

#FROM python:3-windowsservercore
FROM python:3

Restore the default Windows shell for correct batch processing.

SHELL [“cmd”, “/S”, “/C”]
#SHELL [“powershell.exe”, “-NoLogo”, “-ExecutionPolicy”, “Bypass”]
#RUN @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command “[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString(‘’))” && SET “PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin”
WORKDIR /qmetry
COPY . .
CMD [“”]

#ENTRYPOINT [“powershell.exe”, “-NoLogo”, “-ExecutionPolicy”, “Bypass”]
ENTRYPOINT [“python3”]
#CMD [“powershell.exe”, “-NoLogo”, “-ExecutionPolicy”, “Bypass”]

Default to PowerShell if no other command specified.

I am able to built image successfully but running script on it gives error:
make: *** [makefile:55: build_dockerimage_qMetry] Error 1
PS D:\Git_Repo\gitlabTest3> make build_dockerimage_qMetry
docker build -t win-python -f build/Dockerfile-Python .
Sending build context to Docker daemon 1.081GB
Step 1/6 : FROM python:3
—> 4f911a68f83a
Step 2/6 : SHELL [“cmd”, “/S”, “/C”]
—> Using cache
—> 795bca57a83e
Step 3/6 : WORKDIR /qmetry
—> Using cache
—> 1e8080458d4d
Step 4/6 : COPY . .
—> Using cache
—> 18361c0b416a
Step 5/6 : CMD [“”]
—> Using cache
—> 3cd193832dd6
Step 6/6 : ENTRYPOINT [“python3”]
—> Using cache
—> e8fecd7b037f
Successfully built e8fecd7b037f
Successfully tagged win-python:latest

Use ‘docker scan’ to run Snyk tests against images to find vulnerabilities and learn how to fix them
PS D:\Git_Repo\gitlabTest3> docker run e8fecd7b037f
docker: Error response from daemon: container eb46c13e359ff345259b2cd7d5f082af530b15bbf5946978fcb2fbd7c6eb6724 encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)

[Event Detail: Provider: 00000000-0000-0000-0000-000000000000]

[Event Detail: Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: onecore\vm\compute\management\orchestration\vmhostedcontainer\processmanagement.cpp(173)\vmcomputeagent.exe!00007FF7DEDA9F4B: (caller: 00007FF7DED5E13A) Exception(1) tid(38c) 80070002 The system cannot find the file specified.
Provider: 00000000-0000-0000-0000-000000000000] extra info: {“CommandLine”:“python3”,“WorkingDirectory”:“C:\qmetry”,“Environment”:{“PYTHONIOENCODING”:“UTF-8”,“PYTHON_GET_PIP_SHA256”:"f499d76e0149a673fb8246d88e116db589afbd291739bd84f2cd9a7bca7b6

Please let me know what is the gap. I am stuck here. Thanks !

The following worked for me:

FROM python:3.7.4

WORKDIR C:/Startup

CMD [ “python”,“c:\Startup\” ]
print(“The container is alive. Exiting”)

CD to the build directory and:

docker build .

To run:
docker run --rm -it

You should see one line of output which is:
The container is alive. Exiting