Why I use docker for my web dev projects

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so I want to have a little video just kind of explain Docker and why you should be using it on your projects or how you could kind of utilize it to make it easier for other developers to come into a project and be able to hit the ground running without having to like set up a bunch of stuff in their machines um so I have this uh online classroom thing I've been working on during some live streams and in order for other people to kind of jump on and work on this project they would have to set up their own database right so installing postgres on your machine it's not too much work but there is a lot of potential things and snags you can run into depending on your operating system depending on you know the version of Mac you're on or you know just a bunch of variables that can make the experience of setting up postgres difficult right you might have to like run some commands with admin access sometimes you screw stuff up with like permissions you have the CH mod files so this this project here this is the next JS project using the T3 stack but I used a Docker compose file to basically spin up a logo local postgres service right so if I go ahead and just show you that real quick I have a terminal over here and the second terminal here is actual is actually running this Docker compose up so let me just kind of give you a walkthrough of what Docker compose is and how it potentially uses Docker under the hood to run this database so you can specify the image name which I believe if you go to like Docker containers and look for this image postgres there's there's dockerhub.com which actually has a bunch of images on them and you can basically specify what container you want to run or what image you want to run in your local environment um so in this case I'm saying image postgres that's going to go to this postgres image it's going to download it and then it's going to install it and it's going to run it I actually even say install it basically just downloads the image and then it runs it on your machine right so let's show you that real quick if I were to go ahead and just say Docker hyphen compose up now granted I think I have Docker desktop installed so if I go to dock or desktop you will see an application load up that basically shows all your containers all right so over here I have Docker desktop set up on this laptop which you can kind of like dive in and see what containers are running and what images you've downloaded already but when I do a Docker compose up it's actually going to read through this Docker compose file and Docker composes a separate you know CLI tool you have to install and you also have to have Docker installed in your machine but when I run this it basically runs through this yaml file if you're not familiar with the yaml it's basically just like a a more concise way to write Json without having all the curly braces and stuff but it runs through this and it checks to see what services it AKA like what containers you want to spin up it looks at the image and it'll download the image to your machine if you don't already have it so I'm assuming that if I go over to Docker desktop I should have an image over here that's called postgres okay so that's what got downloaded from the Internet it's about 355 megabytes and once it's downloaded you can kind of configure it with environment variables so I'm saying that these are the environment variables I'm going to run the container with in this case I'm saying the user and password is app and app and the database is DB and I can actually kind of connect to that locally using like PG admin or any type of like vs code extension that supports postgres and then you also specify like what ports you want this container to run on um in this case I believe this is the host port and this would be inside the machine so if I wanted to run this database on Port like 8080 on my laptop um and then that would basically map my laptop's 8080 port to the internal Docker containers image of 5432 I believe so that's how you do ports you basically map your host to the actual machine so if I look over here at a I'm going to delete this I don't need that anymore but look over here it's mounting a volume to the docker container as well so this is pointing this DB volume which is defined down here and I believe Docker desktop will kind of show you that volume which will be probably called this one online classroom DB and it's basically linking that that volume which is basically asked like a hard drive that you can attach to your container and it's saying make this postgres service have access to this DB volume and again we're hosting we're mapping the host DB name to a location inside of the container itself so it's kind of confusing if you don't really know much about Docker like you'd have to go and understand it but all of these Docker files they're built up using just a bunch of like uh basically some shell scripts like you can actually dive in to see how the docker file was set up and you'll see that it kind of decides what the base image to use and then it installs a bunch of stuff it might use like apt or apt git to install and update after it does all these things you have like this self-contained image that you can actually run up and have it run postgres or you know you can do the same thing with mySQL if you're doing some other type of database you can do that there's you know open source Docker images for all these different services so the main purpose of all this is I can have anyone clone this project if they have Docker set up and Docker compose they can just run one command they get a database going and then they could just go ahead and just run the service with an npm run Dev and now they're good to go they have a local running database the service is already going to connect to it um and then they don't have to worry about doing any type of configuration because like if you were to go and look up how to install postgres on Mac there's going to be some blog posts or some you know a bunch of steps that you have to do you might be able to brew install it you may not be able to install it you may have to go and like find a package um for your operating system and then every OS will have like a different set of steps you have to follow and for a beginner it's just a real pain if you're more experienced it's not that big of a deal to get these things installed it might burn up 30 minutes or an hour of your time but that's not stuff that you want to kind of waste your time on especially when you're on a team of a bunch of developers and you want them all to have the same consistent code base right you don't want to have to like waste time getting people up to speed setting their machines up when you could literally just give them a Docker compose file and just run up and then they're good to go so hopefully that was like an okay overview of why you might want to use Docker compose on your project or just Docker in general now there's a whole other aspect of Docker and that's like the deployment side of things where you kind of self-contain your um you're executable or like your node app or your Go app or whatever you can put that in a Docker image like you can actually have like a Docker file here and you can build up the things that are needed to run your project so for example let's say I had a node application but it depends on opencv for doing some type of image processing I could actually bundle the DOT dlls to the docker image so that I could just simply deploy that to any environment that has Docker setup but that's a whole nother less than a whole nother like um topic but as far as like just getting the stuff running for local development it really improves your developer experience because you don't have to worry about doing a bunch of stuff and getting a bunch of stuff set up you can just hit the ground running and you're good to go but yeah I think that's all I really want to talk on this video hope this was an okay uh you know introduction to Docker compose you can definitely learn a ton more about Docker and Docker compose and all the different Docker commands but I just want to highlight that like if you're ever working on a project that has like a database if you're installing it manually on your machine just do yourself a favor look a little bit about Docker compose and Docker and just get a database that's set up via Docker compose and you will think yourself in the future anyway have a good day and happy coding
Info
Channel: Web Dev Cody
Views: 30,035
Rating: undefined out of 5
Keywords: web development, programming, coding, code, learn to code, tutorial, software engineering
Id: IaHB838tF3Y
Channel Id: undefined
Length: 7min 55sec (475 seconds)
Published: Wed Oct 05 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.