Debug Django in a docker-compose container with VS Code

I used to use PyCharm Professional to debug my Django projects in a Mac, but now I have to use a Windows PC on my work. However the PyCharm isn’t working very well with WSL2, or at least I couldn’t figure out how. So I turned into VS Code.

VS Code is great, only I couldn’t debug my Django project in a docker container like I did with PyCharm at the beginning. I googled a lot but there is just no a tip to fit my need. Finally I figured it out and I want to write it down to share the way if you have the same needs as mine.

Assuming you know docker very well and have a Dockerfile already.

First the normal docker-compose.yml file

Then for the debugging, you will need a docker-compose-debug.yml file (the whole idea is that command line)

Then you need to add a debug config in the launch.json file

Then that’s it. You can now debug with command:

Wait for the service to finish starting up and then hit F5 in VS Code and it should work.

If no debug, simply go with


Benefits of this way is that:

  1. You don’t need to add any extra debug code into your source code.
  2. The Django hot reload works! No More --noreload --nothreading!

It should work in Mac and Linux too but I didn’t test.

Python developer