Pycharm Remote Debugger for Docker - Debug inside container launched from 3rd party library

已回答
I am looking for a best practice here or thoughts on how I could achieve this. I'm working with the Sagemaker Python SDK. 
 
Goal: I'd like to debug a flask app that runs in a docker container via the pycharm remote debugger. 
 
Problem: A python script on my local machine calls a sagemaker sdk method. This method takes an image name as an argument, then launches a new docker container from the specified image. The container's run command eventually launches the flask app I’m interested in debugging.  Is it possible to attach the debugger to this new container since it is launched via a 3rd party library? 
0

Hi,
I guess using Remote Debug Server is an option, but your script should be able to connect to that server from within the container https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html#remote-debug-config

1
Avatar
Permanently deleted user

Thank you Sergey, 

 

The remote debug server was a good solution in my case. This is really convenient because I can have the flask code call out to the debugger when it executes vs worrying about how I am actually launching the container. 

Just need this in the code somewhere and then setup a remote debugger config in pycharm to wait for the connection. 

import sys
sys.path.append("./debug/pydevd-pycharm.egg")
import pydevd_pycharm
pydevd_pycharm.settrace('host.docker.internal',
port=4200,
stdoutToServer=True,
stderrToServer=True)

Thank you!

-Chris

1

This is great but I have an additional question regarding how to debug contents within a package. For instance, my package is deployed at /opt/python/package/testpackage folder in the remote server and my Dockerfile has an ENTRYPOINT ["test"]. I've added above configuration to the relevant .py file in the package.

Upon starting the debugger, nothing is triggered but I can see in Docker logs that the app has started and is running. Any pointers as to how I can resolve this ?

 

Edit :

I solved it by first creating a remote interpreter and then switching to it. After that, I modified the path mapping in the original Python debug server to map remote and local packages. Then, it worked as expected.

0

请先登录再写评论。