Reusing docker-compose containers in PyCharm

已回答

For performance and other convenience reasons, I'd like to configure PyCharm to use a remote interpreter setup that works by keeping exactly one instance of docker-compose running in the background. In docker-compose terminology, I want PyCharm run configurations to use `docker-compose exec` (execute in running container) rather than `docker-compose run` (instantiate new container and run command in it).

Benefits:
- Reduces overhead of having to start Docker containers every time I fire off a run configuration (server or batch of tests)
- I can edit first-party libraries by installing them with `pip install -e` in the running instance, make changes and push them to Git

Is there an easy way to do this in PyCharm? Or would I have to install an SSH server in my Docker env, do `docker-compose up` in a terminal and then configure PyCharm to use a remote interpreter over SSH?

My current workflow has me run PyCharm inside the container (which is very convoluted) to obtain these benefits, but I know there has to be a better way. Hence this question.

5

Hello Pieter,
Unfortunately, currently it's not possible. There is similar issue about Docker: https://youtrack.jetbrains.com/issue/PY-18901, please, feel free to file an issue about Docker Compose: https://youtrack.jetbrains.com/newIssue?project=PY&clearDraft=true&c=Subsystem+Docker&c=Assignee+Alexander.Koshevoy.

1
Avatar
Permanently deleted user

I see this issue is very old, is this still the same in 2020 ?  

0
Avatar
Permanently deleted user

@Sergey Karpov Do you know if they only have fixed it for phpstorm ? From the post you referred to it is fixed in phpstorm. I am using Pycharm and the problem is still there. Everytime I debug inside a container using docker-compose, my container gets reinstantiated, takes a long time, and most of time I get a timeout error message. If the issue has been fixed in Pycharm, what is the workaround, what settings do I have to adjust? Thank you.

0
Avatar
Permanently deleted user

Any update here ? I tried with the option exec, but debug does not allow it (debug is not available for docker compose exec command), and run option seems to re-instantiate new containers all the time. Tx

0

Same question. I was frequently using this feature in PhpStorm and miss it dearly in PyCharm.

0

Seems like the issue is still there in 2024?

0

@Artem Gordinsky , such setup is not supported yet. Please vote for the corresponding feature request https://youtrack.jetbrains.com/issue/PY-42944 in order to increase its priority and be notified about implementation.

Information on how to use YouTrack: https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications

0

请先登录再写评论。