Jenny
Jenny

Reputation: 121

docker run <image> Error: Can't find python executable to run

I am running a community edition of Docker (Version 18.03.1-ce-win65 (17513)) on Win10 with Linux containers option. I am building an image using docker locally on Windows, and pushing it to Portus, and finally accessing it to run from HPC running Linux using Putty. Well, it turns out that I am unable to run an instance of the created image because of the following error:

python: can't open file './Turn.py': [Errno 2] No such file or directory

This is my Dockerfile that I am using to build an image

FROM python:3.6
LABEL version="1.0"
LABEL build_date="xxx"
LABEL description="xxx"
COPY requirements.txt /
RUN pip install -r requirements.txt
ENV PYTHONIOENCODING UTF-8
# Set the default directory where CMD will execute on HPC
WORKDIR /turn
COPY Turn.py /Turn.py
CMD ["python", "./Turn.py"]

The build process completes successfully as indicated here:

Sending build context to Docker daemon   12.8kB
Step 1/13 : FROM python:3.6
 ---> 5f87764f9df0
Step 2/13 : LABEL maintainer="xxx"
 ---> Using cache
 ---> 71cd96de7015
Step 3/13 : LABEL version="1.0"
 ---> Using cache
 ---> 2fc5cdab38a9
Step 4/13 : LABEL build_date="xxx"
 ---> Using cache
 ---> ae488b87a931
Step 5/13 : LABEL description="xxx"
 ---> Using cache
 ---> cb11a0cf08a2
Step 6/13 : COPY requirements.txt /
 ---> Using cache
 ---> 5ec08f42d1f7
Step 7/13 : RUN pip install -r requirements.txt
 ---> Using cache
 ---> dfa45323647a
Step 8/13 : ENV PYTHONIOENCODING UTF-8
 ---> Using cache
 ---> 733907694a25
Step 9/13 : ENV http_proxy="http://xxx"
 ---> Using cache
 ---> 9b0ba73057ae
Step 10/13 : ENV https_proxy="https://xxx"
 ---> Using cache
 ---> e1ea75915df8
Step 11/13 : WORKDIR /turn
 ---> Using cache
 ---> a8b8ad69d82c
Step 12/13 : COPY Turn.py /Turn.py
 ---> Using cache
 ---> 9f9cb068c16b
Step 13/13 : CMD ["python", "./Turn.py"]
 ---> Using cache
 ---> a7f10949e521
Successfully built a7f10949e521
Successfully tagged turn:latest

SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

I am trying to run this image using the following command:

f@hpclogin1:~> docker run hpcdocker.hpc.xxx.com:5000/namespace/turn:latest 

python: can't open file './Turn.py': [Errno 2] No such file or directory

Upvotes: 3

Views: 2692

Answers (2)

Mureinik
Mureinik

Reputation: 312136

Looks like you're copying Turn.py to the root directory instead of in to your working directory:

COPY Turn.py ./Turn.py
# Was Missing^

Upvotes: 0

dennlinger
dennlinger

Reputation: 11488

This should be a simple path issue. Notice how you call python on ./turn.py? This means you will assume it is a child of the current directory, which is - depending on your entrypoint - not necessarily the root folder where you copied it to.

Simply changing your call CMD ["python", "./Turn.py"] CMD ["python", "/Turn.py"] should resolve the issue.

Upvotes: 1

Related Questions