简体   繁体   中英

Python doesn't find a file within a Docker container

I have an issue that my python program doesen't find a given folder in ubuntu with in a docker container.

First I build my docker container and then I run it which goes without problems until my programm don't find a file. I'm working on a Raspberry pi with Ubuntu Core 16 and Docker to start my python file.

I have found a similar question here and tried their solution:

with open(os.path.join(os.path.expanduser('~'), 'SearchFiles', 'data.csv'), 'r') as csvfile:

But now I get the error:

No such File or directory: 'root/Searchfiles/data.csv'

But the program is the folder ~/usr/git/MVP-Project/Searchfiles/data.csv

Dockerfile for starting the Image:

FROM python:3.6
ADD app.py /
RUN pip install numpy
RUN pip install requests
RUN pip install fake_useragent
RUN pip install datetime
RUN pip install selenium
RUN pip install requests_html
CMD [ "python", "./app.py" ]

So why is it showing the wrong path and how to add the correct path ?

Your data.csv doesn't exist in your Docker Container because you only copy app.py.

ADD app.py /

Move your data.csv to the same directory as app.py and change the command to.

COPY ["data.csv", "app.py", "/"]

If that didn't work try.

COPY . .

With this approach every file of the directory is available inside of your container and therefor you data.csv has to be there. Well as long as you kept it in the same directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM