Cant open a file by it's relative path while the code running from docker container

599 Views Asked by At

I'm looking for help in the issue I have.

In my code I'm trying to open a config file by it's relative path

with open("../config/config.json") as json_config:

This part works great when I'm running it locally (either command line or IDE)

The folder structure looks like this (the running code is in convertor folder):

enter image description here

When I'm trying to run the same code from docker container , I'm getting FileNotFound Error.

FileNotFoundError: [Errno 2] No such file or directory: '../config/config.json'

my Docker file looks like

...
RUN mkdir /app
WORKDIR /app
COPY . .
... 

The config.json is correctly copied to container (all the project correctly being copied)

Thanks for helping here !

1

There are 1 best solutions below

0
On
with open("config/config.json") as json_config:

Forgot that the code is running from the root :)