Recommendations on having multiple Python environments in docker-compose?

Answered

I think I have a pretty common (these days) dev workflow, with multiple docker-compose files.

  • docker-compose.dev.yml -- For running the API, web, etc servers.
  • docker-compose.test.yml -- For running automated regression tests.
  • docler-compose.prod.yml -- You get the idea.

When I'm writing tests and doing coverage, I would use the Python environment in a service specified by "docker-compose.test.yml". However, When I'm testing code in actual use, I would use another service defined in "docker-compose.dev.yml" and its Python interpreter.

For the life of me, I can't figure out how to get this to work well in PyCharm. If I define an interpreter based on docker-compose.dev.yml, then I can't define a separate interpreter in the test dockerfile. I get that it's weird for Python to have "multiple" interpreters, but in actuality they are the same version, same requirements, etc. They just run from different services.

Is this an uncommon approach? How do you all get efficient workflows setup in Docker-compose where you can debug both tests and live code?

3 comments
Comment actions Permalink

Hi,

So the goal is to have different interpreters or switch between services of your docker-compose?

I believe your case is pretty common. There is even an article about similar setup for flask https://blog.jetbrains.com/pycharm/2017/03/docker-compose-getting-flask-up-and-running/

0
Comment actions Permalink

Thanks, Sergey! The blog post is more or less what I'm doing, but the issue is that you'll see the blog configures a remote interpreter under a docker-compose named "web."

In my environment, there would be a service called "web" that might contain the actual wsgi server, but another service named "test" that runs tests. Each service is configured in different docker-compose flies.

0
Comment actions Permalink

Have you tried adding your docker-compose files to your interpreter configuration files?

Compose Configuration in PyCharm

Or this one doesn't cover your needs?

0

Please sign in to leave a comment.