How to remote debug python code in a Docker Container with VS Code

后端 未结 2 608
半阙折子戏
半阙折子戏 2021-01-31 11:20

I\'ve just registered for this question. It\'s about if it\'s possible to remote debug python code in a Docker Container with VS Code. I am having a completely configured Docker

2条回答
  •  终归单人心
    2021-01-31 11:56

    Yes, this is possible - when the Python app is running in a Docker container, you can treat it like a remote machine.

    In your Docker image, you'll need to make the remote debugging port available (e.g. EXPOSE 3000 in the Dockerfile), include the ptvsd setup in your Python app, and then publish the port when you run the container, something like:

    docker run -d -p 3000:3000 my-image
    

    Then use docker inspect to get the IP address of the running container, and that's what you use for the host in the launch file.

提交回复
热议问题