How to Speed up Docker Development! 🐳 Hot Reloading, Debuggers, and More!
Вставка
- Опубліковано 11 чер 2024
- Docker is a powerful tool for building and deploying applications, but when getting started, development can be slow and frustrating... 😡
In this video use a node.js (express.js) API application and show how to improve the development experience by:
1) Enable hot reloading with nodemon and volume mounts
2) Configure the node debugger to work from inside the container
3) Set up docker-compose to encode all of the necessary configuration for development
---
Timestamps:
00:00 - Intro
00:53 - Sample app overview
01:24 - Build + run
02:20 - Rebuilding image to make change
03:38 - Setting up nodemon + volume mounts
06:20 - Setting up inspect debugger
08:07 - Demonstrating debugger usage
09:16 - Defining docker-compose.yaml
---
Join the Community:
💬 Discord: / discord
💻 GitHub: github.com/sidpalas/devops-di...
🐥 Twitter: / sidpalas
👨💼 LinkedIn: / sid-palas
🌐 Website: devopsdirective.com
---
Community size at time of posting:
- Subscribers: 15680
- Channel Views: 477078 - Наука та технологія
Boom! Just what I was looking for. Clear and concise. Thanks man 😃
Thanks, @Simon -- I'm glad it helped! 🎉
I love how you break everything down to understandable elements in your videos!
Thank you for the kind words! 🎉
I love how he's not covering other aspects that even a todo app might have like:
- typescript
- source mapping and debugging typescript
- connecting to a database
- connecting to another service
Brilliant docker tips, nice and to the point! Thank you 👍
Solid tutorial, very clear. Didn’t know how to use the debugger like this.
Thanks Larry! The --inspect switch can be used without containers too and by default it will bind to 127.0.0.1:9229 on your host.
Great video! Thank you for making this, super clear!
Ohhh man, you are a godsend!!! The only docker hot-reload tutorial that really works - by simply breaking the linkage between node_modules and installing nodemon globally in the container! I still have some other problems, but at least you got me working. You made my day, honestly. Sub.
Awesome -- glad to have helped! 🎉
@@DevOpsDirective ...although I don't quite get it, why we need to break the linkage of node_modules in volumes:, if we have node_modules in dockerignore
@@aram5642 .dockerignore will prevent them from being copied in during the build process but they would still get mounted in with the volume mount of my source directory (to enable hot reloading).
Thank you for the explanation, this is what I'm looking for!
I'm new with Docker, but this tutorial was excelent. Thank you so much
This got to be your best video so far, I visit it sometimes just to refresh my mind. May I ask your thoughts on daemonless container engines like podman?
Great stuff! Pretty much exactly what I was looking for and even more.
Awesome!
Just saw your video on the Traversy Media channel. It was very good!
Oh my god thank you so much! I spent all day yesterday on SO trying to find the right parameter to pass in for the volume. This explanation was so much easier to follow, and I feel like I have a better idea of how docker works in general.
Awesome -- currently working on a multi-hour docker deep dive course due out next month! Stay tuned!
@@DevOpsDirective oh sweet! Ya I’ll hang out for that!
is it work on Windows 11?
Its like you understood my problem! Thanks!
Thank you! Subscribed!
🎉🎉🎉
Man!! That's beautiful!
Very nicely explained! Your video was easy to follow and is definitely something I can begin to use in my own work moving forward as I begin to dockerize!
👍 +1 Subscriber
Awesome! Welcome to the Team, Shea! 🤝
Awesome man thanks, exactly what I was searching for. Liked and sub'd!
Awesome, thank you!
Thank you for this. You’re awesome!
You are welcome, @PkmmteXeleon! 🎉
thats just gold, dude! congrats
🏅🙏🎉
Playing with docker. Was frustrated with parameters in "docker run", so thanks for showing docker compose ;)
Yeah it is nice to have all of the configuration encoded in the one file!
immediately hit subscribe after watching your video!
🤝
Nice video !!
Thank you! Cheers!
Nice. Managed to get my project to hot reload (still needed to hit the refresh button on my browser though sadly) once I changed my nodemon run command to nodemon --legacy-watch. Now if only Docker Desktop's beta feature of "Dev Environments" can work properly... 😅
Great Video ... just a quick question ... do you have for prod a different compose/docker file or how do you handle staging? Thanks for a quick response. Cheers!
Yes, if you are using docker-compose to deploy you would want to have other file(s) containing the appropriate settings, ports, env vars, etc... for staging/prod.
If you are deploying via a container orchestrator (such as Kubernetes) those settings would be encoded in your deployment config files.
I did everything as it is done on the video but the hot reload does not work. Am I missing something??
I installed nodemon in the container using this command:
RUN npm install -g nodemon
Don't use compose its a crutch that will bite you later on when you need to do something more complex. Just take that run command stick it in a bash script. Its just as fast and way more extensible for the future
Do something more complex like what
Thanks, and for angular?, can I use nodemon? for hot reloading.
Hey Sir, hope you're fine.
May I ask you a question?
What if I install a dependency, should I always rebuild the container?
Nice video! But we don't need the second volume command as it does not copy node_modules folder. Inspect it using docker exec sh command. And we need to add -L in package.json after nodemon for lagacy commands
I believe this depends if you have node_modules in the .dockerignore file.
I didn't have a .dockerignore file set up in the video making the second mount necessary in that case
Thaaanks!
You're weeelcome!
how to run tests like unit tests, integration tests inside docker containers using jest ?
Thanks!
You’re welcome, Lucas!
Could you please help me how to set it up with Kubernetes with Skaffold?
Hi DevOps Directive - Thanks for this video, but I'm really struggling to get a React/Typescript dockerized app work with hot reload. Do you have a good resource for this case, or can you make a short video on how to deal with that as well?
I haven't looked at it too closely, but this looks like it might be useful medium.com/bb-tutorials-and-thoughts/dockerizing-react-app-with-nodejs-backend-typescript-version-55a40389b0ac
hi Bro, I need somehelp, I've spend my day to figure it out, but on my Windows 11 its does not work..
Hi sir, i am looking for hot reload container for spring bot application please can you share any resources or can create a separate video please
Question: adding node_modules to the .dockerignore woulndn't have the same effect than binding it to a "empty" path as you did?
Placing node_modules in .dockerignore prevents them from being copied in when the image is built, but I dont think it has an effect on whether or not that directory can be mounted in as a volume. This is why I still needed to bind mount it to an empty volume so those local files wouldn't be mounted in when I mount the source.
I could be wrong, but that is my understanding. Feel free to point me to the docs if this is not correct!
Beautiful!
Thank you!
Where from Tennessee? I'm from NC
@@DevOpsDirective Nashville!
@@mikopiko Nice!
Thankyou 🙏🏽
You are welcome, @pramod!
If we don't mount the node modules also at 5:14 wouldn't we have to rebuild the image when we install a new dependency?
Yes, you will have to rebuild when installing new dependencies.
How come that you didn't need to use --legacy-watch flag for nodemon?
thanks man
You are welcome!
Thank you
You're welcome @Gianni!
Hi, can we use dockerignore for ignoring node_modules during volume mount?
Yes! That is a better solution I forgot about while filming this
Sir i am working in fastapi which module i am install in docker file instead nodemon
I havent really used fastapi, but from the docs fastapi.tiangolo.com/#run-it
It looks like you would want to run with a command like: uvicorn main:app --reload
Bless
❤❤❤
It creates a persistance node_module volume so it gets dirty :|
Nice vidéo.. I came from traversty media.. Brad's channel
Awesome, welcome to the team! 😀
@@DevOpsDirective thanks. One question. I am completely new to all these, programming, scripting, coding and softwares in general. Do I need any foundation before becoming a DevOps engineer?
I think it is useful to build a foundation in either development or operations before transitioning to DevOps.
It's not impossible to jump straight in, but having a foundation in one side or the other makes it much easier!
@@DevOpsDirective thanks for the advice.. I should probably start from development..
Hello! Nice tutorial, I am trying to connect this with a MariaDB database (another service in the docker-compose) and I can't.
Any ideas why nodemon still doesnt reload? I rewatched the video like 5 times by now
Tough to say without seeing the code...
If I had to take a guess though, I would go with a problem with the volume mount such that the changes on your host filesystem are not being reflected in the container
@@DevOpsDirective so I actually figured it out, the nodemon command didn't seem to act the way it usually does without docker, so I had to specify for it to watch the src folder with nodemon -L --watch src ...
I'm glad you were able to figure it out! Nice work!
What if we decide to add a new dependency ?
Good question! Whenever you add/change a dependency you need to rerun `docker build` to get those installed into the container image
@@DevOpsDirective Thanks, appreciate the fast response!
What is your name bro?
?… I say it 30 seconds into the video 😅
Thank you
You are welcome @Kishor! 🙏