0

I'm using docker toolbox. I have a python script "prog1.py" on my Windows host machine located at "D:\Werk\Code\Python". And here is my Dockerfile.

FROM python:3
ADD . /usr/src/app
WORKDIR /usr/src/app
CMD [ "python", "prog1.py"]

And here is a clip from my CLI:

D:\Werk\Code\Python> docker build -t python1 .
Sending build context to Docker daemon  64.51kB
Step 1/4 : FROM python:3
 ---> 955d0c3b1bb2
Step 2/4 : ADD . /usr/src/app
 ---> 6fc5184bcfea
Removing intermediate container 89252e9fc17d
Step 3/4 : WORKDIR /usr/src/app
 ---> 6aa9f12ad078
Removing intermediate container b042591d2069
Step 4/4 : CMD python prog1.py
 ---> Running in 8406f3c9fb35
 ---> ecf8ba2e9e0f
Removing intermediate container 8406f3c9fb35
Successfully built ecf8ba2e9e0f
Successfully tagged python1: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.
PS D:\Werk\Code\Python> docker run -it python1
<Expected output of the script>
PS D:\Werk\Code\Python> docker run -it -v /d/Werk/Code/Python:/usr/src/app python1
python: can't open file 'prog1.py': [Errno 2] No such file or directory

When I run the image without binding, it works but when I run it with the bind instruction it shows Erno 2.

What am I doing wrong?

Aayush Pathak
  • 159
  • 11
  • Could you please try `ADD /usr/src/app /usr/src/app` rather than `.` ? – jagatjyoti Jul 19 '17 at 07:09
  • Also you have to use `EXPOSE` and the `-p` argument. – Klaus D. Jul 19 '17 at 07:28
  • @J.Mishra The first argument of ADD is the host location, as I mentioned my host is windows and my file is located at D:\Werk\Code\Python – Aayush Pathak Jul 19 '17 at 10:17
  • @KlausD. Are you sure I have to expose ports even if I'm not doing any network activity? – Aayush Pathak Jul 19 '17 at 10:21
  • @Aayush Pathak The error says it's unable to get the file which means either the `ADD` which does a copy did not work or you have to specify the full path of python program in `CMD`. Don't think `EXPOSE` is needed until your python app is some kind of web app and has to do something with ports. – jagatjyoti Jul 19 '17 at 11:58
  • @J.Mishra Don't think that full path is needed. In this tutorial video the guy just uses directories. https://www.youtube.com/watch?v=YFl2mCHdv24 – Aayush Pathak Jul 19 '17 at 12:10

0 Answers0