Both Dockerize and be able to debug a Django app using vscode

Is it possible to both Dockerize a Django app and still be able to debug it using Visual Studio Code's debugging tool? If yes, how? E.g, using docker-compose to run Django app, postgres, and a redis instance and be able to debug the Django app via Visual Studio Code.

Thanks in advance

Yes, this is possible.

I've done it with a NestJs app and should be a similar setup.

Expose a specific port on the Django app service in the compose file first.

Create the launch.json file the following configuration, then replace <port-exposed-on-container> and <directory-on-container> with real values.

{
    "version": "0.2.0",
    "configurations": 
    [
      {
        "name": "Docker: Attach to Node",
        "type": "node",
        "request": "attach",
        "port": <port-exposed-on-container>,
        "address": "localhost",
        "localRoot": "${workspaceFolder}",
        "remoteRoot": "/<directory-on-container>",
        "protocol": "inspector",
        "restart": true
      },
    ]
}
Back to Top