简体   繁体   中英

How to debug python code using vs code by attaching to a running container (without Dockerfile)?

I want to be able to debug python code in D:\Tools\sima\source after running: docker run --rm -it -v ${PWD}:/mnt -w /mnt sima-sdk:latest /bin/bash Then I open VSCODE and do attach to running container.

This opens a second VS Code window in that container as shown in the picture below: enter image description here

Then I select the python interpreter within the docker /usr/bin/python3 Now I want to run the debugger. I creates a launch.json file as below

    {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python: Current File",
                "type": "python",
                "request": "launch",
                "program": "${file}",
                "console": "integratedTerminal",
                "justMyCode": true
            }
        ]
    }

and my python code is very simple:

    a = 4
    b = 7
    c = a* b
    print("c is equal to", c)
    print("Hello test 1 ")
    print("Hello test 2")

When I set a breakpoint in the python code editor and run the debugger, nothing seems to happen although the variable and watch windows are showing up enter image description here

Can I get hep to understand what I am doing wrong if anything please? I have googled a lot without results Thanks in advance

Set your "justMyCode:false" . This can make your code sotp at breakpoint:

{
    "name": "Python: Current File",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "justMyCode": false,
    "console": "integratedTerminal"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM