Debugging Python in Docker using VSCode

  Рет қаралды 38,023

That DevOps Guy

That DevOps Guy

4 жыл бұрын

Subscribe to show your support! goo.gl/1Ty1Q2 .
Patreon 👉🏽 / marceldempers
Good day folks! In this video we'll take a look at debugging python code inside docker containers using VSCode remote debugging!
Like and Subscribe!
Also if you want to support the channel further, become a member 😎
marceldempers.dev/join
Checkout "That DevOps Community" too
marceldempers.dev/community
Source code:
github.com/marcel-dempers/doc...
Follow me on socials
Facebook | thatdevopsguy
Twitter | / marceldempers
GitHub | github.com/marcel-dempers
LinkedIn | / marceldempers
Instagram | / thatdevopsguy
Music:
Track: Grouf - PIPED UP /w Lord Sesshomaru
Listen: / piped-upw-lord-sesshomaru
Track: Lucid Monday - Soudiere - Hollow Tips
Listen: / soudiere-hollow-tips
Track: JASON RICH - A BAY BAY | is licensed under a Creative Commons Attribution licence (creativecommons.org/licenses/...)
Listen: / abaybay

Пікірлер: 49
@khaledarja9239
@khaledarja9239 2 жыл бұрын
taking debugging to a whole new level.. THANKS!
@aike.h.2323
@aike.h.2323 3 жыл бұрын
The most DevOps guy I've ever seen, not even python installed locally :D
@guillermomoran-arreola5372
@guillermomoran-arreola5372 2 жыл бұрын
Finally! I am debugging Python in Docker! You're awesome! Thank you :)
@tonyBeloni
@tonyBeloni 4 жыл бұрын
Clear concise and well explained. Thank you
@johnkntran
@johnkntran 3 жыл бұрын
Excellent content as always and very useful! P.S. If you are running VSCode inside the container (rather than on your local machine) via the VSCode Remote Extension, the debugging setup is a little different. There is no "portMapping" section needed from your localhost to the remote host. They've also upgraded PTVSD to DebugPy since. Keep making great stuff!
@marekczarnecki5388
@marekczarnecki5388 4 жыл бұрын
Appreciate your work. Really relevant to my current work. Thank you
@MarcelDempers
@MarcelDempers 4 жыл бұрын
Amazing thank you! I am interested to know what other topics and areas you are working on. Will help me gear future content for you. Don't hesitate to let me know 👍🏻👍🏻😁
@mikevictorecho
@mikevictorecho 4 жыл бұрын
Great, this finally works. I tried so many things to debug into a flask docker environment. I tried ptvsd before without luck, i tried remote containers, etc.
@marxman1010
@marxman1010 3 жыл бұрын
Remote containers seems not work with breakpoints. Using ptvsd and python extension is the best way to debug app inside containers. Remote containers need improvement.
@filipdevelter9163
@filipdevelter9163 2 жыл бұрын
Absolutely well done. Thank you.
@mciccozz
@mciccozz 3 жыл бұрын
AMAZING video! thank you so, so much!
@AlexandreShimono
@AlexandreShimono 3 жыл бұрын
Awesome video! Question: if I do not use the "wait", can I still attach the debugger to the container?
@jplobianco
@jplobianco 3 жыл бұрын
Great video. Thank you!
@leescottdavis
@leescottdavis 4 жыл бұрын
This is great. Thank you
@viniciusandd
@viniciusandd 4 жыл бұрын
Thanks man. Great content.
@plaguekriz
@plaguekriz 4 жыл бұрын
Thanks - very helpful
@nailsonlandim
@nailsonlandim 4 жыл бұрын
Huge thanks! I could setup here in a container with a complete diferent scenario. It's a Video traffic recognition using CUDA/GPU Again, Huge Thanks!
@muhammadinaammunir6761
@muhammadinaammunir6761 3 жыл бұрын
Very nice video. Subscribed
@grcdeepak1
@grcdeepak1 2 жыл бұрын
Great! Can you do a video on debugging a Kubernetes python application ?
@flamed7s
@flamed7s 2 жыл бұрын
Keep up the good work 👏
@ALaaHamoudah
@ALaaHamoudah 3 жыл бұрын
Thank you for the video, I did the same configs but for a file not a server, it runs the debugger but I can't see anything in the variables and watch, and it also not stoping on a breakpoint
@raavimanoj1
@raavimanoj1 Жыл бұрын
@That DevOps Guy can we debug aws lambda (python) created using container image with the same approach? We can do with AWS SAM template but wondering can we directly debug the Lambda Container using the same approach?
@bzouchir
@bzouchir 3 жыл бұрын
how do you get this to work for a pyramid application that serves using 'pserve'? any help or direction would be appreciated!
@ruiw4263
@ruiw4263 4 жыл бұрын
This is very useful. but just wonder if any code change on your local src will be reflected and live loaded into your running docker?
@MarcelDempers
@MarcelDempers 4 жыл бұрын
Hey friend, thank you! So the way i approach docker development is I mount the code into the container, so short answer is yes, the code changes on your host are the same as inside the container. However, the process like flask etc, needs to be reloaded (stopped, started) in order to reflect the code changes. Some web servers can auto reload by using file watching. I have done this in nodejs in an upcoming video but I am sure Python web servers can do the same. Hope it helps and glad you found it useful 💪🏽
@Slygon28
@Slygon28 3 жыл бұрын
Thanks - that's awesome ! It's important to note the ptvsd is deprecated in favor of debugpy :)
2 жыл бұрын
I'm not 100% sure because it took some tries before working, but here's what I had to change in the Dockerfile to make debugpy work: 1. RUN pip install debugpy -r requirements.txt 2. CMD python -m debugpy --listen 0.0.0.0:5678 --wait-for-client -m flask run -h 0.0.0 -p 5000
@tree2rhym
@tree2rhym 2 жыл бұрын
my question is how can I connect to container which is already running ? It seems like vs code starting new container in debug mode instead of connecting with existing one
@pingyang8963
@pingyang8963 Жыл бұрын
Thanks for the real example, actually there is one thing to update to make it running, in the requirements.txt, using Flask == 2.0.3 instead.
@jayhawkelectrical
@jayhawkelectrical 4 жыл бұрын
Hi Marcel, fantastic video! I have this setup with my project but I cannot get it to hit any of the breakpoints I have defined.
@jayhawkelectrical
@jayhawkelectrical 4 жыл бұрын
I'm getting this error in the Log (Window): [error] 'setBreakpoints' request must be issued after 'launch' or 'attach' request.
@jayhawkelectrical
@jayhawkelectrical 4 жыл бұрын
I figured it out, github.com/microsoft/ptvsd/issues/2077
@jagan4269
@jagan4269 4 жыл бұрын
Beautiful article. Hearty thanks. Quick question: To run on non debug mode (prod), i changed the target from `debug` to `prod` and fired `docker-compose up`, i get the following message (basically stuck on Attaching) ▶ docker-compose up Recreating my-python-flask-playground ... done Attaching to my-python-flask-playground Am i doing anything wrong? Any tips or tricks are highly appreciated. Thanks!!!
@MarcelDempers
@MarcelDempers 4 жыл бұрын
Thank you 🤓 So the "recreating" message means docker is recreating the container since technically the debug and non debug modes are two different containers. The reason it "hangs" there is because its running in foreground mode so you'll see stdout messages. If you want it to run in background mode, start it with 'docker-compose up -d' Hope that makes sense 🙂💪🏽
@jagan4269
@jagan4269 4 жыл бұрын
@@MarcelDempers Thank you.
@jagan4269
@jagan4269 4 жыл бұрын
I think the mistake that i was doing was not changing the image name. Now i have 2 images (1 for debug and other for prod). Works like a charm now. Once again thanks for this awesome video.
2 жыл бұрын
I'm not 100% sure because I tried a little to make it work, but here's what I had to change in the Dockerfile to replace ptvsd with debugpy: 1. RUN pip install debugpy 2. CMD python -m debugpy --listen 0.0.0.0:5678 --wait-for-client -m flask run -h 0.0.0 -p 5000
@dylangonzales
@dylangonzales 4 жыл бұрын
Having some trouble setting this up with an inherited docker django web project, could I get some advice please?
@MarcelDempers
@MarcelDempers 4 жыл бұрын
oooo django can be trickier than flask, but I'd look for a popular debugger to use for it. Seems like a good one is PDB. Key is to open the right debugging port in the container and host so your external debugger can attach. I've not got much experience with Django, but upon first glance you'd want to follow something along these lines medium.com/@vladyslav.krylasov/how-to-use-pdb-inside-a-docker-container-eeb230de4d11
@rayhanmuktader1064
@rayhanmuktader1064 4 жыл бұрын
Did you ever get it to work?
@dylangonzales
@dylangonzales 4 жыл бұрын
Rayhan Muktader no still nothing, my dockerfile isn’t structured correctly for implementing multi stage builds. Changing it messes up a lot of stuff and I can’t afford to run that risk with something in production right now. Just debugging with trace command and chrome dev tools
@plaguekriz
@plaguekriz 4 жыл бұрын
For django run line will be: CMD python -m ptvsd --host 0.0.0.0 --port 5678 --wait --multiprocess /code/manage.py runserver 0.0.0.0:8000
@suzusi4992
@suzusi4992 3 жыл бұрын
how to put breakpoint in docker code
@illiakailli
@illiakailli Жыл бұрын
I'm afraid this is not possible, but you can use the alternative approach described in this article blog.devgenius.io/how-to-debug-docker-build-6c2588401188
@richardclark4111
@richardclark4111 4 жыл бұрын
Hey there! Very cool video. Thx from Ukraine )) Could U describe how U use different options in the Dockerfile (dev/prod). And how Build Dockerfile from docker-compose cli with different settings?
@MarcelDempers
@MarcelDempers 4 жыл бұрын
Thank you 💪🏽 In the Dockerfile, take a look at what's called Build ARG's which gives you capability to pass arguments at build time into the build process. You can then pass these on the CLI too 🤓
@richardclark4111
@richardclark4111 4 жыл бұрын
@@MarcelDempers Got it! Thanks 👊
@maikfischer7407
@maikfischer7407 3 жыл бұрын
Algo comment:)
@alchemist2059
@alchemist2059 3 жыл бұрын
Hi guys .Very cool video.The debugger runs but it does not hit any of my breakpoints.Here is my project: github.com/BrianSandiford/REST-API-DOCKER-SQLALCHEMY.git: Any help would be greatful.
FastAPI debugging inside docker
8:52
Codenama
Рет қаралды 3,2 М.
Kubernetes pod autoscaling for beginners
13:22
That DevOps Guy
Рет қаралды 31 М.
Final increíble 😱
00:39
Juan De Dios Pantoja 2
Рет қаралды 37 МЛН
ДЕНЬ РОЖДЕНИЯ БАБУШКИ #shorts
00:19
Паша Осадчий
Рет қаралды 6 МЛН
Заметили?
00:11
Double Bubble
Рет қаралды 3,4 МЛН
ONE MORE SUBSCRIBER FOR 6 MILLION!
00:38
Horror Skunx
Рет қаралды 15 МЛН
Debugging a Dockerized Django app with VSCode
23:22
London App Developer
Рет қаралды 34 М.
Learn Docker in 12 Minutes 🐳
12:01
Jake Wright
Рет қаралды 2,1 МЛН
Python dataclasses will save you HOURS, also featuring attrs
8:50
How to configure PostgreSQL | Learning | DevOps
24:00
That DevOps Guy
Рет қаралды 6 М.
President Donald Trump's border wall with Mexico takes shape
9:29
CBC News: The National
Рет қаралды 7 МЛН
Learning PostgreSQL | an Introduction | DevOps
16:34
That DevOps Guy
Рет қаралды 8 М.
100+ Docker Concepts you Need to Know
8:28
Fireship
Рет қаралды 787 М.
Dockerize your Development Environment
12:26
Codú
Рет қаралды 79 М.
Introduction to Service monitors for beginners | Kubernetes monitoring
19:39
Эффект Карбонаро и бумажный телефон
1:01
История одного вокалиста
Рет қаралды 2,7 МЛН
cool watercooled mobile phone radiator #tech #cooler #ytfeed
0:14
Stark Edition
Рет қаралды 8 МЛН
wireless switch without wires part 6
0:49
DailyTech
Рет қаралды 1,2 МЛН
wyłącznik
0:50
Panele Fotowoltaiczne
Рет қаралды 24 МЛН
Mi primera placa con dios
0:12
Eyal mewing
Рет қаралды 576 М.