Skip to content

Debugging Docker-Compose Connecting Issues - Need to Press F5 2x #3252

@luongjames8

Description

@luongjames8

I followed the instructions in: #1765 to get VsCode debugger to attach to my docker-compose project.

I use command": "docker-compose up -d' with the-dflag withintasks.json, and then reference this task within launch.jsonas apreLaunchTask`.

It generally works, but there's a slight minor annoyance in that I actually have to press F5 twice to run the process twice.

The first time I press it, it seems to spool up the container in the background, but somehow the debugger isn't able to connect, and it gets stuck. I've set it to wait for the debugger so nothing happens.

> Executing task: docker compose -f docker-compose.debug.yml up -d <

[+] Running 1/1
 - Container goldhill_backtest_goldhillbacktest_1  Started                                                                                 2.5s

Terminal will be reused by tasks, press any key to close it.

Then, I have to press F5 again, It re-executes the above task, and then the debugger is able to connect.

> Executing task: docker compose -f docker-compose.debug.yml up -d <

[+] Running 1/0
 - Container goldhill_backtest_goldhillbacktest_1  Running    

Some other observations:
(1) If I remove the -d background flag from docker compose then this run-twice workaround doesn't work.
(2) I can of course execute docker compose -f docker-compose.debug.yml up manually, and then run the debugger (after removing the prelaunchTask). But this is two steps and makes fast debugging slow.

Any idea what I'm doing here? It would seem that if I applied some time-out before the debugger tried to connect, which gave enough time for the Docker Container to spin up, would do the job. That is my working hypothesis at the moment.

        {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "preLaunchTask": "Compose Up",
            "restart": true,
            "port": 5678,
            "host": "localhost",
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}/python",
                    "remoteRoot": "/app"
                }
            ],
            "logToFile": true
        }
`

`
		{
			"type": "shell",
			"label": "Compose Up",
			"problemMatcher": [],
			"command": "docker compose -f docker-compose.debug.yml up -d"
		},
	]
version: '3.4'

services:
  goldhillbacktest:
    image: goldhillbacktest
    build:
      context: .
      dockerfile: python\Dockerfile
    command: ["sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 ./src/main.py "]
    ports:
      - 5678:5678
    volumes:
      - type: bind
        source: ./python
        target: /app 
      - type: bind
        source: ./python/data
        target: /app/data 
      - type: bind
        source: ./python/src
        target: /app/src   

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions