Accessing files properly within docker container

Viewed 31

I am trying to access a csv file in my project. The file is not located in the same place relative to the working directory. When running my app in a docker container the file system remains the same, however accessing the files becomes different.

These files are hosted locally on the container itself, it is not on a volume.

I have a python project running in a docker container. Accessing the files looks like this:

df = pd.read_csv('/app/test-files/'+filename)

However when I run it locally with 'py main.py' I can access the files using this:

df = pd.read_csv('/test-files/'+filename)

Is there a way to make it so I can access the files on both local and container filesystems using the same pathing syntax?

1 Answers

While building the image create the directory under "/" and copy the file to "/test-files/" directory. Post that you can run the python file as per your requirement

df = pd.read_csv('/test-files/'+filename)
Related