Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging linked docker containers when using docker-compose

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.

like image 832
Torsten Engelbrecht Avatar asked May 21 '15 18:05

Torsten Engelbrecht


1 Answers

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

like image 169
quickinsights Avatar answered Nov 05 '22 23:11

quickinsights