How to create a great dev environment with Docker

  Рет қаралды 250,586

Patrick Loeber

Patrick Loeber

Күн бұрын

How to create a great local Python development environment with Docker. Learn about Docker Volumes, Docker Compose, how to debug in containers, and more.
Repo: github.com/patrickloeber/pyth...
Timeline:
00:00 - Introduction
02:03 - Why Docker?
04:02 - Dockerize an app
10:25 - Immediate file changes (Docker volumes)
13:08 - Use IDE in Docker container
17:38 - Docker Compose
25:54 - Debug inside Docker container
Get my Free NumPy Handbook:
www.python-engineer.com/numpy...
✅ Write cleaner code with Sourcery, instant refactoring suggestions in VS Code & PyCharm: sourcery.ai/?... *
⭐ Join Our Discord : / discord
📓 ML Notebooks available on Patreon:
/ patrickloeber
If you enjoyed this video, please subscribe to the channel:
▶️ : / @patloeber
~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~
🖥️ Website: www.python-engineer.com
🐦 Twitter - / patloeber
✉️ Newsletter - www.python-engineer.com/newsl...
📸 Instagram - / patloeber
🦾 Discord: / discord
▶️ Subscribe: / @patloeber
~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~
🅿 Patreon - / patrickloeber
#Python #docker
----------------------------------------------------------------------------------------------------------
* This is an affiliate link. By clicking on it you will not have any additional costs, instead you will support me and my project. Thank you so much for the support! 🙏

Пікірлер: 186
@scriptkiddie100
@scriptkiddie100 Жыл бұрын
Thank you for this. Very comprehensible and through, ideal for a beginner tutorial.
@heyydev_1
@heyydev_1 Жыл бұрын
Amazing explanation. Even though my native language is not English, this is the best tutorial I've found and the one that I understood the best. Thanks!
@heyydev_1
@heyydev_1 2 ай бұрын
I was just about to comment how great this video is and I saw I commented the same a year ago 😂 Thanks again. Now I'm a senior developer and these things keep been high value.
@techatival
@techatival Жыл бұрын
So far my favourite introduction to Docker. Thank you!
@yaksvk
@yaksvk Жыл бұрын
Thank you Patrick! This was one of the clearest, straight-forward and concise introductions to Docker for people who actually do development and not just devops/admin stuff. Very helpful!
@Javoke
@Javoke Жыл бұрын
I wanna thank you for aaaaalll the videos you share with us. Me, as a non-english-native person, I appreciate the rythm and accent in your voice, so we can understand exactly what you are saying. Also,, the explanation is very clear !! Thank you so much!!!
@NileGold
@NileGold Жыл бұрын
This was so simple, I didn't even realise that the video was 30 min :), thank you for this
@mogyiman
@mogyiman 6 ай бұрын
Awesome content and clear presentation; special thanks for the debugger setup!
@scigama71
@scigama71 Жыл бұрын
Superb. Thank you. This was very clean and straight to the point. Subbed.
@brendan8915
@brendan8915 Жыл бұрын
This is the video that has finally got me over the line for using Docker. I needed to upskill this for work, my sincerest gratitudes to you. Thank you so much.
@DenisRasulev
@DenisRasulev Жыл бұрын
Thanks a lot for the great, short and to the point video with excellent explanations!
@sixpooltube
@sixpooltube 8 ай бұрын
Amazing tutorial. Fast and easy to understand.
@dimahodan232
@dimahodan232 Жыл бұрын
best on-point video I have seen in the last few months on YT.
@brandonrich4956
@brandonrich4956 Жыл бұрын
Thank you! Excellent video. Easy to follow.
@AlexCaranha
@AlexCaranha Жыл бұрын
Good Job! Amazing tutorial, Patrick. Thanks a lot!
@tamirsalem76
@tamirsalem76 2 ай бұрын
Brilliant tutorial, concise yet very complete.
@dogbusiness5201
@dogbusiness5201 Жыл бұрын
Thanks for the video. Just started the course on Docker so this one was extremely relevant
@Mutombo71
@Mutombo71 Жыл бұрын
use podman instead, it is the future
@GrayCo
@GrayCo Жыл бұрын
Great video and impressive understanding of the subject matter.
@UnUnkn0w
@UnUnkn0w Жыл бұрын
great video, thanks! a lot of value for 30 minutes !!
@ujefmalek77
@ujefmalek77 Жыл бұрын
आपके वीडियो सुपर कूल और अद्भुत हैं। मुझे यह बहुत पसंद आया. धन्यवाद
@cexploreful
@cexploreful Жыл бұрын
Wow i wanted to learn Docker! Thx again Patrick!
@NavneetaSinha
@NavneetaSinha Жыл бұрын
Thank You so much Patrick for this vodeo, this was the much needed video for me right now
@sabaokangan
@sabaokangan Жыл бұрын
Thank you so much for sharing this with us ❤️‍🔥
@ronjones1587
@ronjones1587 2 ай бұрын
This is all I need and you gave it perfectly ! Thank you very much !
@tedlazar
@tedlazar Жыл бұрын
Dear Patrick, thanks a lot for the great tutorial !!!
@JiriPocta
@JiriPocta 4 ай бұрын
Thank you very much, simple and easy to understand.
@jasynskyi
@jasynskyi 7 ай бұрын
Great explanation! thank you for your work
@baopeng
@baopeng Жыл бұрын
Very detailed! Cool stuff!
@murtadha96
@murtadha96 Жыл бұрын
Brilliant! Thank you for this video
@jiangpengli86
@jiangpengli86 21 күн бұрын
Thank you for this great tutorial.♥
@polydeuces01
@polydeuces01 Жыл бұрын
Great Demo I even managed to to do it on my windows machine.
@chineduezeofor2481
@chineduezeofor2481 Жыл бұрын
Excellent tutorial!
@vengtCent
@vengtCent Жыл бұрын
Hi Patrick, thanks for this great tutorial. Do you have any resources for setting up this environment with pycharm?
@angtranhai6457
@angtranhai6457 Жыл бұрын
Very helpful sir!
@vivarantx
@vivarantx Жыл бұрын
thanks patrick , you are a genius!
@janaeshkrish
@janaeshkrish Жыл бұрын
Nicely done 🎉
@mohssineserraji1098
@mohssineserraji1098 7 ай бұрын
Thank you for the amazing tuto
@MohammadMahdian888
@MohammadMahdian888 Жыл бұрын
Awesome tutorial
@navneetchourasiabgt
@navneetchourasiabgt Жыл бұрын
Great content dude 😎
@alvarovs89
@alvarovs89 Жыл бұрын
Hi Patrick! I've been following you for a few months, and thanks for everything you share. Just a quick question, what do you use in the terminal of vs code that show you the suggested code? like autocompletion? thanks again :)
@abdullahsaid4765
@abdullahsaid4765 Жыл бұрын
try zsh
@NostraDavid2
@NostraDavid2 Жыл бұрын
I love the powerlevel10k wizard, that asks you which features / settings you want. Much easier than trying to customize bash until it looks like Zsh with p10k.
@RNikSan
@RNikSan Жыл бұрын
Super, thanks a lot!
@ventin75
@ventin75 Жыл бұрын
exactly what i needed
@vadymesch2267
@vadymesch2267 2 ай бұрын
Great one!❤‍🔥❤‍🔥❤‍🔥
@brennenherbruck8740
@brennenherbruck8740 Жыл бұрын
Devcontainers have prebuilt configurations that are *much* simpler and gives your container superpowers with devcontainer feautres (like docker-in-docker)
@Lexaire
@Lexaire Жыл бұрын
Yes, using non-dev images like he showed is an awful dev experience. Much better to use the premade ones for development, and then custom dockerfiles just for final testing and deployment.
@madferretx
@madferretx Жыл бұрын
Can you give examples of good premade dev environment? anything for javascript?
@madferretx
@madferretx Жыл бұрын
@@Lexaire Can you give good examples of premade dev environment? one for javascript? thanks
@muxahx3096
@muxahx3096 Жыл бұрын
agreed + you can actually debug in container (use break points )
@chriskeo392
@chriskeo392 11 ай бұрын
​@@Lexaireneed more!
@geraldbustos
@geraldbustos Күн бұрын
Buenisimo!
@datawolk
@datawolk Жыл бұрын
When you build the release container for distribution, will it strip out the vs code stuff? Or do you have to do this manually or isnt that necessary?
@FilSerge
@FilSerge Жыл бұрын
You need just rebuild image with code updated. That's it.
@danielk.2172
@danielk.2172 Жыл бұрын
Good tutorial! If anyone on Windows using Git bash having problems to see the reload of the local code, try mounting the volume with: -v /${PWD}:/code Apparently there is a POSIX path conversion that doesn`t convert correctly and ends up adding a ";C" at the end of the local path
@josephrobineau1662
@josephrobineau1662 Жыл бұрын
you sir are a good man
@guilhermemendes264
@guilhermemendes264 8 ай бұрын
Thanks bro I owe you a beer
@budmonk2819
@budmonk2819 8 ай бұрын
Thank you brother - I almost gave up before I decided to search through the comments.
@timkochanski
@timkochanski Жыл бұрын
Great tutorial. Is anything additional required when docker compose yaml references multiple containers forming a network? Can I just connect to my UI container and debug through all the other referenced containers as if they were just imports and I had justmycode set to false? Or do we need to edit other container docker files... Maybe adding port 5678 for example?
@BrettKromkamp
@BrettKromkamp Жыл бұрын
Great beginner tutorial. Thanks for this.
@michaelestrinone2111
@michaelestrinone2111 Жыл бұрын
@Patric - it will be a great learning video about the same subject but geared towards C# developers with either SQL Server as a backend or MySQL etc.
@DeathBean89
@DeathBean89 Жыл бұрын
I'm not a C# dev, but you could probably modify the Dockerfile to pull the image for the current .NET version and then RUN any commands to set up the environment. Then you could modify the docker-compose file and replace the redis service with a SQL Server or MySQL one. Forward the appropriate ports, make sure that your volumes are correct, and you should be good to go. I'm sure there are plenty of resources out there to get you going. Good luck!
@lune0409ify
@lune0409ify Жыл бұрын
Thank you! :)
@DanielF847
@DanielF847 Жыл бұрын
Great tutorial and cool way to leverage containers! Have you found any methods for doing this using open-source or even source available tooling? :-/ Microsoft appears to have restricted the Docker and dev-environment extensions to their proprietary closed-source release of vscode (Microsoft visual studio code)... Great to see Microsoft back to their old tricks 😩
@DanielStoehr203
@DanielStoehr203 Жыл бұрын
Hey Patrick, Thanks for the video. Do you know if developing inside docker Container is working With the community Edition of pycharm?
@chikken007
@chikken007 Жыл бұрын
Could we also setup the debugger with the suggested "fastapi" option of VSCode?
@recaseng
@recaseng Ай бұрын
Thank you ^^
@AmodeusR
@AmodeusR 2 ай бұрын
Very interesting video. Although it lacks some clarifications on the docker commands, this gap could be filled by ChatGPT helping me out understand what they were exactly. Thanks for the video
@kingdsl
@kingdsl 11 күн бұрын
For those who are asking about the VS Code theme, I believe it's 'Shades of Purple' by Ahmad Awais ⚡
@timelschner8451
@timelschner8451 Жыл бұрын
Question: when you directly connected the IDE inside the cotainer, do you still need the mapping, since you are already in the IDE inside the container?
@patloeber
@patloeber Жыл бұрын
you probably still also want it on your machine and need a mechanism to persist the changes. But if, let's say you push your code from the container to Github, then you don't need the mapping
@timelschner8451
@timelschner8451 Жыл бұрын
I see and thanks for the informative video!
@elmarhinz3076
@elmarhinz3076 Жыл бұрын
In the moment of mounting the outside Volume, there should be similar code inside the container. (We know this, as we were able to run it without mounting the outside code.). I miss some words, how this conflict is solved. * What happens to the code inside the container when editing the mounted code? * Why do we copy the code at all, if we plan to mount it? * Wouldn't it make sense to throw an error message from inside, similar: "Error 501: The source volume was not mounted"? Otherwise duplicated code may lead to many mistakes by editing the wrong place. * Is there any standard or practice, how to handle this?
@FilSerge
@FilSerge Жыл бұрын
> What happens to the code inside the container when editing the mounted code? it is substituted with anything new in project directory. > Why do we copy the code at all, if we plan to mount it? to be able to share it. You can commit all editing done to update the image.
@FilSerge
@FilSerge Жыл бұрын
That is cool to have all your dev workflow as Dockerfile and to build it whenever/wherever you want. But it's such pain in the ass not to forget installing zsh shell, all vs code extensions, etc. Tried to set it all for my ml project, but failed.
@igorlikholat5606
@igorlikholat5606 Жыл бұрын
brilliant tutorial! thank you I have a question.. I’m confused with how to debug worker command inside docer container, when it possible to run in bash console only? I’m going to be glad hearing your answer)
@kimsanov
@kimsanov 11 ай бұрын
At 12:46 when we attach volume - did main.py copied inside container according to Dockerfile instruction?
@user-yy7el7vg8s
@user-yy7el7vg8s 2 ай бұрын
Hi, Thanks for this tutorial, it's great! I would like to do the same in pycharm - but it appears that docker-based envs are a premium-only feature. Is that correct or it's possible to do the same also with the community edition of Pycharm?
@tt4m
@tt4m Жыл бұрын
Good♥️♥️💛شكرا
@commievoyager
@commievoyager Жыл бұрын
Nice exploration! But could you do the same using just a docker-compose? Why do you prefer the way using Dockerfile? What benefits does it have?
@Remolhunter97
@Remolhunter97 7 ай бұрын
Not sure what you mean, but you need multiple separate dockerImages, each for a different process, and then docker compose to organise all the different dockerImages you have, and run them all at the same time
@jasonnn12
@jasonnn12 Жыл бұрын
What's the extension used that suggests full command in the terminal? seems pretty handy
@przbadu
@przbadu Жыл бұрын
I use zsh-autosuggestions, is this is what you are looking for
@lawrencedoliveiro9104
@lawrencedoliveiro9104 Жыл бұрын
2:13 A container is actually _less_ than a whole VM. It’s a complete prepackaged userland, that runs under the same Linux kernel that is already installed on your machine. It is not actually an OS on its own.
@nguyenhieu6995
@nguyenhieu6995 7 ай бұрын
I am quite new to docker. In the example at 21:00, there is a duplicate in command (Dockerfile and docker-compose), should it be duplicated like that or not?
@sadamabbasi1574
@sadamabbasi1574 Жыл бұрын
Sir, What python IDE and autocomplete extensions you have used in Intermediate Python Course ? Kindly share
@Mathias-cq3zo
@Mathias-cq3zo Жыл бұрын
It is the one that's included with the python extension in VSC (the Python extension Patrick showed us)
@tensorflow5330
@tensorflow5330 Жыл бұрын
hello , as I know that docker volumes map the local machine folder Linux or MacOs is different to window 10/11. in windows 10/11 cannot be directly mapped to a local directory
@sebastianmolitor4827
@sebastianmolitor4827 Жыл бұрын
Great video. Thank you for this fast foward track on "docker developing". But I have one stuoid beginner qestion: How do I get my changed code from inside the container? 🤔
@martinstojcevski9585
@martinstojcevski9585 Жыл бұрын
You can always copy the code from the container. But in the video he is explaining about container volumes, which will mirror both local and the container code, so whatever is changed in the code of the container it will be mapped to the local code
@lawrencedoliveiro9104
@lawrencedoliveiro9104 Жыл бұрын
7:17 Having a list of strings is a good idea. This avoids having to pass a shell command, with all the possibilities for (mis)interpretation of special characters. Instead, you pass the command-line words directly to the program, as is.
@hdcamsit2144
@hdcamsit2144 Жыл бұрын
@patloeber do you think it makes sense to develop python packages inside docker?
@cexploreful
@cexploreful Жыл бұрын
i want to know it too
@lawrencedoliveiro9104
@lawrencedoliveiro9104 Жыл бұрын
12:34 Does the COPY command in the Dockerfile become superfluous when you define a volume?
@ClAddict
@ClAddict Жыл бұрын
Only if you don’t want to actually use the docker image in any production environment.
@haithammaged987
@haithammaged987 Жыл бұрын
thanks🤩
@Didanihaaaa
@Didanihaaaa 10 ай бұрын
is this different for Flask? Also could you show how to deploy a CNN model and make it work? how do you post an image to trigs the app? do you include the CNN model (sometimes it is heavy) into the image? what if it is big size? Bests
@IsayanBros
@IsayanBros Жыл бұрын
I have been using docker compose for project setup for years now and have been happy with it. However, as soon as I switched to an M1 Macbook, startup speeds have been pretty bad.
@FilSerge
@FilSerge Жыл бұрын
Is it because m1? What have gone wrong?
@mirwek
@mirwek 6 ай бұрын
Interesting, you are using Fastapi. How can you debug with debugpy Flask application in docker since you need to give security PIN?
@anisyacoubi
@anisyacoubi Жыл бұрын
thanks Patrick, am I the only one who's not getting anything when i run the command "docker run --name docher-container -p......". I've changed the port though to 8000:8000 due to an error on 80 but the localhost isn't accesible, any idea where i could be wrong please
@elmarhinz3076
@elmarhinz3076 Жыл бұрын
Each time the container is rebuilt the editors extension have to be installed again. Here the workflow feels a little broken. Any best practice how to address with this? How to do it within a multi developer project?
@FilSerge
@FilSerge Жыл бұрын
Yeah, such a bummer. You need to add some lines in Dockerfile for installing z-shell and vs code extensions.
@ChedyChaaben
@ChedyChaaben Жыл бұрын
12:41 If you experience a problem when executing the command, try adding two double quotes like this : docker run --name fastapi-container -p 80:80 -d -v "$(pwd):/code" fastapi-image
@insolentflunkey
@insolentflunkey 9 ай бұрын
Thank you!
@jeffiscowCS
@jeffiscowCS 7 ай бұрын
true hero
@tonybengue
@tonybengue 7 ай бұрын
Thanks for that tutorial sir 🔥 When I want to connect to my container throught Dev Containers, it opens the root folder instead of the code folder (thanks to workdir command in the Dockerfile), and I don't understand why.
@rahulmitra9476
@rahulmitra9476 Жыл бұрын
For those of you stuck at 12:18 take note that the brackets are curly brackets
@mpsii
@mpsii Жыл бұрын
Can you provide an update on using podman or containerd? My company has prevented us from using Docker due to corporate licensing costs. I am using virtualbox/vagrant now, but do not like the "integration" of vagrant into virtualbox
@mpsii
@mpsii Жыл бұрын
@@mspajic My company has said "No" to docker due to licensing for company (not personal) use.
@mspajic
@mspajic Жыл бұрын
@@mpsii I think you didnt understand me, docker engine is free even for companies, just docker desktop (gui app) isnt, these arent the same things, CLI versions policy hasnt been changed. Read the docker subscription model on their official site. I even checked with my company, as we had the same situation, and I got green light after this explanation.
@mspajic
@mspajic Жыл бұрын
Ah I get it, sry I misunderstood you. Company isnt using docker anymore as a tool in general and you dont get anything by installing it on pc. Sry again, was just tryin to help :)
@sakkakuppi5637
@sakkakuppi5637 Жыл бұрын
Why I am having 'ModuleNotFoundError/ when trying to import function from a file I created?
@irondragon0385
@irondragon0385 Жыл бұрын
Would it be possible to do this for Visual Studio (not Code)?
@kimsanov
@kimsanov 11 ай бұрын
Why at 9:00 in Dockerfile wi didn’t have to use EXPOSE instruction?
@sseymour1978
@sseymour1978 Жыл бұрын
When using this approach you end up with 2 VScode projects open at the same time. And for some reason I can connect to debugger only from host VScode and not from container.
@khanra17
@khanra17 Жыл бұрын
1st: pwd & cwd are different 2nd: doesn't install redis in the current container but starts a different container
@eliluong
@eliluong Жыл бұрын
can vscode connect to remote container on another host?
@cantoncotton2229
@cantoncotton2229 20 күн бұрын
Something I don't understand. Why do we need to copy the code to the container if we are later mounting pwd to the container? The code which is in the image is not used anyway right? Also how does it work without EXPOSE 80 in the Dockerfile? Is it optional?
@albincr
@albincr 7 ай бұрын
What about other langs like go or rust?? and it too much tied up with vscode? can we configure some other editors???
@Mutombo71
@Mutombo71 Жыл бұрын
does this also work with podman?
@ZIKAZIKA-nu4ih
@ZIKAZIKA-nu4ih Жыл бұрын
12:57 My changes to code are not reflected unless I restart the container. Can you please suggest why is this ?
@jeffzzz7850
@jeffzzz7850 Жыл бұрын
I also have this problem.
@tiagobovolin
@tiagobovolin Жыл бұрын
Attaching to running container opens Vs Code on an empty folder. How to I fix this?
@sakkakuppi5637
@sakkakuppi5637 Жыл бұрын
Click File > Open Folder... and select the folder
@AkaThePistachio
@AkaThePistachio 3 ай бұрын
Im having issues attaching to my running container, once connected im put inside an empty dir with no access to my code any advice?
@olivierwarnier969
@olivierwarnier969 8 ай бұрын
Hi, thank you I'm alone with problem in 14:30 ? : when I start VSCode in dev container "fastapi-container" I don't have any sources, and when I open folder VSCode re-open local version. Working on macOSX Ventura 13.5.2 - VSCode 1.82.3 latests version of Docker and dev container extensions
@kreten780
@kreten780 5 ай бұрын
Same problem, there is an error when setting up the whole opening code inside of a container. Did you solve it? I am getting Error reading shell environment. Error: stream ended with:0 but wanted:9
@akshayboddhul
@akshayboddhul Жыл бұрын
Which vs code theme used?
@elhusseinali8934
@elhusseinali8934 Жыл бұрын
could you share with us the name of your vscode theme
@Xertish210
@Xertish210 Жыл бұрын
which İDE do you use
How To Use Docker To Make Local Development A Breeze
21:53
ArjanCodes
Рет қаралды 297 М.
Never install locally
5:45
Coderized
Рет қаралды 1,7 МЛН
FOOLED THE GUARD🤢
00:54
INO
Рет қаралды 61 МЛН
Неприятная Встреча На Мосту - Полярная звезда #shorts
00:59
Полярная звезда - Kuzey Yıldızı
Рет қаралды 5 МЛН
Python 3.11 has two NEW math functions!!
0:48
Patrick Loeber
Рет қаралды 33 М.
Learn Docker Quickly - Machine Learning Project for Absolute Beginners
25:31
Best Platforms to Host Python Apps (for free!!)
9:50
Patrick Loeber
Рет қаралды 107 М.
Learn Docker in 7 Easy Steps - Full Beginner's Tutorial
11:02
Fireship
Рет қаралды 1,8 МЛН
Supabase Crash Course For Python Developers
39:58
Patrick Loeber
Рет қаралды 35 М.
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,7 МЛН
How To Set Up Local DevOps Environment With Docker using Dev Containers
13:37
My Favorite Way To Handle Dev Environments | VS Code Devcontainers
30:05
Using docker in unusual ways
12:58
Dreams of Code
Рет қаралды 406 М.