Lets assume I have the following docker-compose.yml
file running two different python apps in parallel (e.g. via flask):
app1:
command: python app.py
build: app1/
app2:
command: python app.py
build: app2/
links:
- app1
app2
is linked to app1
since I want to get particular data from app1
within it. Now my problem is a certain scenario where I want to debug this link. I can easily debug app1
and app2
as standalone containers (via docker-compose run --service-ports ... python app.py
and placing pdb
somewhere in the code). My problem is when I want to debug app1
in case the request comes from app2
. If I start app1
with docker-compose run
, then app2
is not able to resolve the link. This issue becomes even more a problem with more apps/services "talking" to each other depending on their links.
Is there a good way to handle this? How do you approach the debug problem with linked containers in general (not necessarily python specifc)? Thanks for the input.
If you're doing development locally on the same machine then you can add a net: 'host'
into your configuration which does the following:
Tells Docker to skip placing the container inside of a separate network stack. In essence, this choice tells Docker to not containerize the container's networking!
For more info see the documentation
app1:
command: python app.py
build: app1/
net: 'host'
app2:
command: python app.py
build: app2/
net: 'host'
Additionally you should start your app1 in daemon mode and app2 in the foreground mode for debugging purposes:
docker-compose up -d app1
docker-compose run app2
As soon as you get a request from app1 to app2 you will drop down to (pdb) in app2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With