# How i can run python script from Docker container

**URL:** <https://forums.docker.com/t/how-i-can-run-python-script-from-docker-container/108988>\
**Category:** Docker Desktop\
**Tags:** windows\
**Created:** [May 13, 2021, 6:40pm UTC](https://forums.docker.com/t/how-i-can-run-python-script-from-docker-container/108988 "2021-05-13T18:40:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jyotidgs](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jyotidgs](https://forums.docker.com/u/jyotidgs)\
**Post date:** [May 13, 2021, 6:40pm UTC](https://forums.docker.com/t/how-i-can-run-python-script-from-docker-container/108988/1 "2021-05-13T18:40:39Z")

</div>

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

My docker file:

# escape=`

# Let us use PowerShell line continuation.

#FROM [Microsoft Artifact Registry](http://mcr.microsoft.com/dotnet/framework/sdk:4.8)  
#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(‘[https://chocolatey.org/install.ps1](https://chocolatey.org/install.ps1)’))” && SET “PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin”  
WORKDIR /qmetry  
COPY . .  
CMD [“Qmetry.py”]

#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 [“Qmetry.py”]  
—\> 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.  
CallContext:[\Bridge\_ProcessMessage\VmHostedContainer\_ExecuteProcess]  
Provider: 00000000-0000-0000-0000-000000000000] extra info: {“CommandLine”:“python3 Qmetry.py”,“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 !

---

<div class="post-metadata">

**Author:** ![awb12768](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@awb12768](https://forums.docker.com/u/awb12768)\
**Post date:** [May 19, 2021, 8:58pm UTC](https://forums.docker.com/t/how-i-can-run-python-script-from-docker-container/108988/2 "2021-05-19T20:58:35Z")

</div>

The following worked for me:

dockerfile:  
FROM python:3.7.4

WORKDIR C:/Startup

COPY OneOutput.py .  
CMD [“python”,“c:\Startup\OneOutput.py”]

OneOutput.py:  
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
