Run code on docker in a specific path

I am trying to running my project using a docker image. I tried with many configuration, but I always end up with no files on the container.

The project on my local machine (Mac) is at a certain path /Users/myuser/project
I want the project to be "copied" (actually I'd like to use volume binding) in the /app path of the container.

 

My Configuration:

  • I haven't set any path mapping in the project interpreter
  • See attached image for the project configuration
0
6 comments

Try to create a new run/debug configuration and run it with all default parameters. Does it work? 

Volume binding is configured in docker container settings field, which is empty on your screenshot. Path mappings should be configured if the script is already inside the image. 

0

It works. I can even change the "Docker container settings" to map the project to the desired path /app on the container:

Docker container settings: -v /Users/myuser/project:/app

However, as soon as select the option "Run with Python Console" it stops working as it gives me the following error in the Python console:

Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/opt/.pycharm_helpers/pydev/_pydev_bundle/pydev_umd.py", line 193, in runfile
os.chdir(wdir)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/myuser/project'

How should I change the configuration to run the code in Python Console? Could it even be an "issue" related to the Docker image?

0

You probably need to tiker with [File | Settings | Build, Execution, Deployment | Console | Python Console] settings. Try setting the working directory there.

0

Could you explain me the different between Working Directory, Path Binding and the Volume Binding on Docker?

0

Volume binding is a docker-specific setting, while path mapping and working directory is PyCharm-specific. 

The console is not working with docker container out of the box because of a known issue: https://youtrack.jetbrains.com/issue/PY-22650

The workaround is to setup path mappings in python console settings.

0

Please sign in to leave a comment.