binding ports with docker-compose and run configurations


Working in a Django project I may have many Python processes running at once: a shell process, a celery worker, tests, in addition to the Django server.

The project's Python Interpreter is set to use Docker Compose.

If I point it at a docker-compose service that binds no ports, I cannot connect to the Django server from my web browser.

If I add a `ports` section to that docker-compose service, the first thing I start grabs that port, and when I attempt to run other things they fail with 


Error running 'run server' com.github.dockerjava.api.exception.InternalServerErrorException: {"message":"driver failed programming external connectivity on endpoint proj_service_1 (...): Bind for failed: port is already allocated"}


How is this supposed to work?

1 comment

Am I right that you have at least two Run configurations in PyCharm: Django server and Django tests? Could you please explain in details how do you start the other things ("a shell process, a celery worker")?

In theory you could set several port bindings in ports section for your "web server" service in the docker-compose.yml and use different ports in different places.

I should notice that each PyCharm Run configuration (including Django server and Django tests) use docker-compose up command which results in inability to run server and tests in parallel. But you can use Django console in PyCharm along with running server or tests because it uses docker-compose run.


Please sign in to leave a comment.