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

11 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:

 

1
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
Comment actions Permalink

I was trying to use a remote docker interpreter. The host machine is remote. The setup was successful, however, I found it impossible to sync my local source with the container. 

I just want to confirm that this thread is talking about the case when the docker engine is still local. There is no way to set up "true" remote docker development because we cannot bind a local source directory to a container running on a remote docker host. 

It seems to me that the only way to accomplish this is to use an ssh remote interpreter with FTP source sync.  

Am I getting this right? 

 

0
Comment actions Permalink

Hi Sergei, my use case is exactly like the OP described (using the docker container purely as an interpreter/debugger). What is the best practice for granting the container access to my project? Should I grant access in the Dockerfile, or in the Pycharm settings....or something else?

Thanks!

 

0
Comment actions Permalink

Jetty

The best practice is just as Sergey described, using volume bindings in the run/debug configuration.

0

Please sign in to leave a comment.