Recommendations on having multiple Python environments in docker-compose?


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

  • -- For running the API, web, etc servers.
  • docker-compose.test.yml -- For running automated regression tests.
  • -- 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 "" 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, 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?

Comment actions Permalink


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

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.

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?


Please sign in to leave a comment.