简体   繁体   中英

In VSCode, 'Python: Remote Attach' fails to connect to a running Docker Container

Good evening,

I have a container which is running and ready to connect. In VSCode I've tried to 'Attach Visual Studio Code' to open a new Dev Container, select the sources, hoping I can debug. I'm unable to select breakpoints and the code isn't running. Nothing happens.

I've also tried 'Python: Attach Remote'. Nothing happens and there's no errors.

Launch.json:

       {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "connect": {
                "host": "0.0.0.0",
                "port": 3000
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "."
                },
            ]
        }

Docker Compose.yml

 services:
      sfunc:
        image: sfunc
        build:
          context: .
          dockerfile: ./Dockerfile
        command: ["sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --log-to-stderr --wait-for-client --listen 127.0.0.1:3000 home/site/wwwroot/TimerTrigger/__init__.py "]
        ports:
          - 3000:3000

How could I troubleshoot this?

Thank you

等待连接

Those hostnames didn't work for me. Using localhost in the launch.json and 0.0.0.0 as the host in the --listen option worked.

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