Debugging a Dockerized Django app with VSCode

preview_player
Показать описание
How to create and debug a Django app that runs in Docker when using VSCode.

Resources:

00:00 - WHY we use Docker
01:36 - What we’re doing in this tutorial
01:57 - Installing dependencies
02:58 - Create new directory to use for project
03:35 - Open project in VSCode
03:48 -Add README.md file
04:07 - Add .gitignore file for the Python project
04:58 - Creating a Django project within our directory
06:18 - One line command to create Django project in Docker
10:50 - Create the template Docker configuration files in VSCode
13:00 - Modify the template files
14:07 - Modify our Docker file
15:58 - Build our Docker image
16:30 - Start our service
17:02 - Make changes to Docker compose file so VSCode debugger works
17:48 - Change the launch file
18:57 - Test the debugger tools
19:13 - Add a new sample Django view to use for testing
20:30 - Place a breakpoint in code to test
21:18 - Testing the debugger
Рекомендации по теме
Комментарии
Автор

How can I resolve the problem "Import "django.http" could not be resolved from source VSCode does not allow the import of the django library added to the docker container.

vostbur
Автор

i got this error when i debugging. a debug stop at line in the manage.py. the error message is "Exception has occurred: OperationalError
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
psycopg2.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?


The above exception was the direct cause of the following exception:

File "d:\django projects\recipe-app-api\app\manage.py", line 18, in main

File "d:\django projects\recipe-app-api\app\manage.py", line 22, in <module>
main()
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?"

fitnessislive
Автор

Doesn't work for me, the debug console turns orange for like a second and stops. I wonder because I've followed all the steps

charliesta.abc
Автор

I have issue when run debug: timed out waiting for launcher to connect

antoniomourao
Автор

This seems to fail when I'm already using postgres for my project, is there any way to fix this error:

connection to server on socket failed: No such file or directory
Is the server running locally and accepting connections on that socket?

When I check docker ps my database is in fact running on 5432 and healthy. Thanks!

AllPsychBouldering
Автор

Great video, thank you!
I'm using PyCharm myself, but I picked up a couple of interesting Docker nuggets from this like the user part.

silkogelman
Автор

I am getting the error "Debug Adapter Executable not provided" error after executing docker command. App doesn't execute in debug mode. Please help.

SadashivaNarayana
Автор

Helped so much on doing the same with odoo tnx

sofianeamr
Автор

Not seem to use docker-compose debug though, but mentioning it makes confusion.

rodionbykov
Автор

I have a problem:
1. Added a service "db" in docker-compose.yml with postgres image.
2. When referencing the "db" in django's settings.py, the vscode debug shows error, where it says there is no "db" host.
Do you know what it can be?

markera
Автор

When I tried applying this to my project I got an error in VSCode 'Invalid message: "pythonPath" is not valid if "python" is specified'.

I decided to instead clone your repository to try and play about with debugging with your exact code. However, I get the same error message there too?

Any help would be great!

yates
Автор

Thanks for the video
I need to learn docker

alexblack
Автор

did not understand, when you click on run and stat debugging how visual studio knows where to connect ?
how it knows that I have to connect to container end point instead of starting it locally?

treerhym
Автор

Awesome! Exactly what I was looking for...

eduardolucas
Автор

Hello, can you tell me if it is possible to work on vs code using Django modules auto-import? I assume that by entering, for example, LoginView and pressing Ctrl+Space, a suggestion will appear to import this class from internal Django modules, if, for example, I do not know where exactly in which module it is located. Please help me..

xviqkmw
Автор

Great tutorial
I am so glad to discover this channel

mimocrocodile
Автор

This is a great tutorial and the blog version is great, too. This is about the 5th of similar tutorials that i've tried. Perhaps most of them ran correctly at some time, but I couldn't follow them through to completion now. Of course, I might have misunderstood something or done something wrong, too.

But what I was really looking for was a tutorial like this using PyCharm and targeting Virtual Box. I couldn't get any of those to work for me, but I am hoping what I learned here will transfer. I can't do much about the Virtual Box requirement, but I am okay with using Code if that is the easier path.

BruceCichowlas
Автор

It takes me 30 seconds to enter the debugging mode inside the contain, is there a way to speedup the startup? Thanks

jarorkwong
Автор

Hi Mark!
I completed your course of Django Advance in udemy
How to make that exiting project to run in VS code debug mode?
and I found issue that I have to user from app.core.models import Recipe
to get auto suggestion from VS code which lead to give error in project so I need to remove app. from it how to solve that also

MukundPatel
Автор

Thank you very usefull! but it doesn't reload the code when modified as it happen outside the docker. Is there a way to get the code reloaded during debugging?

damianofranco