Тёмный

How to debug Docker containers! (Python + VSCode) 

DevOps Directive
Подписаться 60 тыс.
Просмотров 44 тыс.
50% 1

I recently encountered an issue where a python unit test was passing inside of a container, but failing locally.
In this video I show a few different tips/techniques for debugging code running within a docker container:
1) Modify the container entrypoint and exec into the container
2) Copy files to and from the container for inspection/comparison
3) Set up a remote debugger inside the container and attach to it from the host
I hope you find these helpful as you debug your own containerized applications.
Cheers!
---
Join the Community:
💬 Discord: / discord
💻 GitHub: github.com/sidpalas/devops-di...
🐥 Twitter: / sidpalas
👨‍💼 LinkedIn: / sid-palas
🌐 Website: devopsdirective.com
---
Timestamps:
0:00 - Intro
0:57 - Sample test case overview
1:12 - Sample Dockerfile
2:28 - Tip #1 (modify entrypoint)
4:00 - Tip #2 (docker cp)
5:39 - Tip #3 (remote debugger)
7:16 - Configuring debugger in VSCode
8:54 - Closing thoughts
---
Community Size at Time of Posting:
- Subscribers: 225 🎉
- Channel Views: 3715

Наука

Опубликовано:

 

28 май 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 50   
@datamike7457
@datamike7457 3 года назад
Nice video. I've been exploring docker containers and the extra abstraction makes debugging more awkward. This was super helpful!
@DevOpsDirective
@DevOpsDirective 3 года назад
Thanks Mike! Relevant to your area of expertise, containers can be a game-changer for eliminating dependency issues for data science work: - Have a legacy model that is still living in the past and requires Python 2.7? No problem! - Need different versions of TensorFlow various applications you are developing? Sure! - Calling out to some 3rd party tool that only runs in Linux? Great!
@betas1001
@betas1001 3 года назад
@@DevOpsDirective Hi i got Error: -m: missing , is this correct? ENTRYPOINT ["python","-m","debugpy", "listen", "0.0.0.:5678", "--wait-for-client","-m"]
@akozy
@akozy 3 года назад
This is what I was looking for!!! It seemed so hard to find for some reason. Can't wait to see your channel grow. Keep it up!
@DevOpsDirective
@DevOpsDirective 3 года назад
Well, I'm glad you found your way to my little corner of RU-vid! 😁 Welcome to the team! 👋
@TuomoKankaanpaa
@TuomoKankaanpaa 3 года назад
Wow the remote debugger and attaching it to vs code will really come in handy! And congrats on the 200 subs 🙌🎉
@DevOpsDirective
@DevOpsDirective 3 года назад
Thanks! -- Yes, it takes a bit of work to have the separate Dockerfile stage, but for debugging complex issues it is really the way to go!
@AZIARGROUS
@AZIARGROUS 2 года назад
Thank you man! This is exactly the kind of concept I was playing with these days. Thank you for explaining how to expose that port from docker to local host.
@DevOpsDirective
@DevOpsDirective 2 года назад
You are welcome, Paolo!
@thebluechimera
@thebluechimera 3 года назад
Great video! I've always found Docker quite intimidating, this was good to watch
@DevOpsDirective
@DevOpsDirective 3 года назад
Thanks @Maria! It is a bit of a steep learning curve, but once you get used to it, the added confidence that something in production will behave the same way as on your laptop is amazing!
@thebluechimera
@thebluechimera 3 года назад
@@DevOpsDirective I know right! Quite an awesome feeling
@kab9996
@kab9996 3 года назад
Thanks for the best and the clearest tutorial on how to debug python into Docker with VSC !
@DevOpsDirective
@DevOpsDirective 3 года назад
Woot! Thanks @Ka -- your comment makes me smile :)
@machinelearningid3931
@machinelearningid3931 3 года назад
From traversy, thanks, your devops video are awesome.
@DevOpsDirective
@DevOpsDirective 3 года назад
Welcome aboard @Machine Learning ID! 👋👋👋 Happy to have you here!
@plashless3406
@plashless3406 2 года назад
This is really amazing. I'm having a use case would really appreciate for helping me out. :) I'm running services in Docker Containers i-e web, db, worker(celery). Is there any way so that I can add a breakpoint in the Pycharm(code) and it will start the debugger in the containers(specifically celery worker)?
@ShikhaSingh04
@ShikhaSingh04 2 месяца назад
Can you suggest any other dependency for debugging else than debugpy?
@user-nu4so7zg8r
@user-nu4so7zg8r Год назад
Great video, thanks !
@DevOpsDirective
@DevOpsDirective Год назад
You're welcome! 🎉
@user-bq4do4fo2q
@user-bq4do4fo2q 2 месяца назад
I have my dockerfile made and Im using fastapi python but when I run my application via that play button of VSCODE I run into a error called PYTHON PATH IN YOUR DEBUG CONFIGURATION IS INVALID. please help me with that ..
@abrahammathewos9917
@abrahammathewos9917 3 года назад
Thank you! you are the best.
@DevOpsDirective
@DevOpsDirective 3 года назад
Thank you @Abraham! Comments like this make me want to keep putting out even better videos!
@SgtMajorJay
@SgtMajorJay 3 года назад
Your videos are fire
@DevOpsDirective
@DevOpsDirective 3 года назад
Thanks @SomeDude! 🔥🔥🔥
@mariacristinaarezzi
@mariacristinaarezzi Год назад
I'm happy to meet you
@yuriwolf6234
@yuriwolf6234 3 месяца назад
Dear Sid, do I have to rebuild the docker image every time I modify something in my .py file? thanks regards
@yuriwolf6234
@yuriwolf6234 3 месяца назад
just answering myself: I got to mount the :/app directory on the container to a path on my local machine where i copy my files docker run -v /path/on/local/machine :/app -p 5678:5678 image_id main_python_file
@eddydewaegeneer9514
@eddydewaegeneer9514 2 года назад
I would like to see a tutorial that describes how to debug python code mapped from outside the docker (using the -v parameter)but running inside a container for which I have only the container (and not the Dockerfile)
@danh_phuong9297
@danh_phuong9297 2 года назад
That's great. I'm looking for debugging C in docker with VSCode. Please suggest any solution !!!
@DevOpsDirective
@DevOpsDirective 2 года назад
One options would be to have a multi-stage image with an extra Debugger stage in which you install any of your favorite debugging tools. This way you can keep your production image small but have an image to recreate any bugs in that has the necessary tools for debugging
@nareshmp1
@nareshmp1 2 года назад
Nice video. Is it possible to debug the code step by step? Especially when its web2py app?
@DevOpsDirective
@DevOpsDirective 2 года назад
Once you have attached the debugging session as shown in the video you should be able to step through to any breakpoints you set!
@acavaelnick
@acavaelnick 2 года назад
Great, thanks
@DevOpsDirective
@DevOpsDirective 2 года назад
You are welcome, @Joaquin!
@uncoding_with_raj
@uncoding_with_raj Год назад
Can we connect VSCODE debugger AUTOMATICALLY to docker container without hitting the play button in VSCODE ?
@jansoriano7451
@jansoriano7451 3 года назад
Hi Sid, I've seen your video tutorial on Brads channel. I'm currently a shopify dev, and I want to become a devops engineer. I am hoping to get tips from you or your channel. Thanks!
@DevOpsDirective
@DevOpsDirective 3 года назад
Hi @Jan - Happy to have you here! Welcome to the team! 👋👋👋
@jansoriano7451
@jansoriano7451 3 года назад
@@DevOpsDirective Thanks Sid!
@edustreamimg
@edustreamimg 3 года назад
good job buddy!
@DevOpsDirective
@DevOpsDirective 3 года назад
Thanks @Eduardo!
@edustreamimg
@edustreamimg 3 года назад
@@DevOpsDirective In 6:35 you are creating 3 images?
@DevOpsDirective
@DevOpsDirective 3 года назад
@@edustreamimg Yeah, here is more info on multi-stage builds docs.docker.com/develop/develop-images/multistage-build/ By using the --target option when building the Dockerfile I can tell Docker which of the stages I want it to build (docs.docker.com/develop/develop-images/multistage-build/#stop-at-a-specific-build-stage)
@edustreamimg
@edustreamimg 3 года назад
@@DevOpsDirective Is a good practice not to run debugger in same container? why?
@DevOpsDirective
@DevOpsDirective 3 года назад
@@edustreamimg There are a number of reasons you wouldn't want to have a debugger running inside your production container. The three that come to mind are: 1) Simplicity -- Each container should have a singular focus. By adding a debugger, you lose that. 2) Security -- It's best not to have additional surface area for potential attackers to try and exploit (you would need to open an additional port to access, etc...) 3) Performance -- having the debugger running is one more thing to take compute cycles away from your application RU-vid comments are a bit clunky for technical discussions. I have a discord server if you want to continue the discussion with lots of other smart folks! discord.gg/CQYSqKvqqa
@kid_kulafu_1727
@kid_kulafu_1727 3 года назад
Who’s here because you saw this dude on brads channel? Thank you for this sir.
@DevOpsDirective
@DevOpsDirective 3 года назад
Hi @aRtoo _ -- Welcome! 😄
@jarorkwong8042
@jarorkwong8042 2 года назад
Volumn up
@DevOpsDirective
@DevOpsDirective 2 года назад
Thanks, this was before I had figured out the whole audio recording/editing thing... 😅 Hopefully my newer videos have better, more consistent audio!
Далее
Debugging a Dockerized Django app with VSCode
23:22
Просмотров 34 тыс.
1🥺🎉 #thankyou
00:29
Просмотров 22 млн
Never install locally
5:45
Просмотров 1,6 млн
Get Started with Dev Containers in VS Code
6:59
Просмотров 93 тыс.
Debugging Python in Docker using VSCode
11:15
Просмотров 37 тыс.
How To Use Docker To Make Local Development A Breeze
21:53
How to Use a Debugger - Debugger Tutorial
17:01
Просмотров 287 тыс.
Different Ways to Run Dev Containers: VS Code vs CLI
5:22
Golang: Debug docker & kubernetes containers
13:02
Просмотров 1,4 тыс.
Индуктивность и дроссель.
1:00