Mapping local dir when using docker interpreter

Answered

Hi all,

I try to debug code I have on my local system using docker container as my interpreter. My code uses some local files during its run, these files located on my local system but not in the container. Basically the container is used just as an environment. When I try to run my code it doesn't recognize the files I try to read, how can I map my local dir to debug my code (same as you can do when using ssh remote interpreter)?

System:

Ubuntu 18.04

Pycharm 2019.3 

Python 3.7.4

8 comments
Comment actions Permalink

You can add your custom Volume Bindings in your run configuration (Run | Edit Configurations... -> Docker container settings).

If you store those files inside the project, make sure the Path Mappings of the interpreter are correct (File | Settings | Project | Project Interpreter).

0
Comment actions Permalink

So basically the only possibility is to place the files within the project? What if that can't be done?

 

0
Comment actions Permalink

It is possible to use files that are located outside of your project by adding the needed directories as Content Root in File | Settings | Project | Project Structure and configuring the corresponding Volume Binding in your Python run configuration. Example:

 

0
Comment actions Permalink

Hi Sergey,

Thank you for your detailed explanation, how do I get to the second menu? will it work even if the container is running on a remote server? (if not what should I do?)

0
Comment actions Permalink

Go to Run | Edit Configurations...  menu, choose your Python run configuration (or create one) and there you will see this Docker container settings field.

No, PyCharm doesn't support running Docker on the remote machine yet https://youtrack.jetbrains.com/issue/PY-33489

But in the description of that feature request, you can find a workaround. Not sure if it covers your case though.

0
Comment actions Permalink

Sorry for annoying but I can't see "Docker container settings" field under my Python run configuration. Maybe first I need to set my project interpreter to be a docker container one? (if that is the case then I understood)

 

About "PyCharm doesn't support running Docker on the remote machine yet" this will be really helpful! waiting for it.

 

Thank you very much!

0
Comment actions Permalink

Yes, you are right, you should switch to Docker interpreter first. Sorry I didn't mention that.

0
Comment actions Permalink

Thank you! 

0

Please sign in to leave a comment.