What is Docker? Why it's popular and how to use it to save money (tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey tech leet here and welcome back to another episode today we are going to talk about the newest and latest trend in software engineering developer operations docker continued ization today we are drinking tea it is actually one of my favorite concoctions so what I thought I would do in this video is first tell you what is docker give you a little brief introduction about containers and all that explain about why it's used for while we're going to be using that today and then we're going to actually do some server maintenance and use docker to save myself a little bit of money in my actual daily operations that I do on the websites and apps I run so first of all what is Stucker docker is a trend it is a very hot trend in software engineering and not actually software engineering but I would say more in the developer operations side where you deal with systems engineering scalability actually in day to day operations many software engineers aren't going to necessarily touch this site but it changes the way that we write server software these days by the way this video is sponsored by algo expert the IO slash tech lead they're an excellent resource check them out for video tips on coding interview practice covering data structures algorithms and time space complexity use code tech lead for an additional discount okay docker essentially takes your operating system and then splits it into many self-contained areas where applications can run in it's a lot like a virtual machine if you've heard of this term before where people will take a single operating system and then divide it into many small operating systems each one thinking that they're running on their own system well the problem with traditional virtual machines has been that it's very heavyweight and it takes a lot of resources and you don't really want to run too many on the single system it just overloads everything docker brings this abstraction up one more level such that it's not operating quite at that level and more on the application level all it really is is like a command-line tool and you just say docker run and then the name of the application that you want to run like PHP sent OS Debian bash my sequel and you can choose the application and we just run it in its own contained space so that's what docker is it's a self-contained space for applications to run now why can't this be interesting well I think a lot of people including myself are still grasping at trying to understand what docker is good for where it can be used but I can tell you two key reasons that I figured out the first reason has to do with how it allows you to structure your apps and write code in a different way and then the second reason has to do with scalability so with structuring your apps what it lets you do is it contains your app in a certain space now this is interesting because when I would normally create a web application I would install a bunch of random programs onto the server after a while I didn't really know what I had installed on there and one thing I always thought was well I have this website with a bunch of software and tools and installed programs on a certain machine and for example if I ever wanted to sell this website to somebody else I always wondered how would I do that I'd have to sell the server and the lease on the server as well and then they'd have to pick up the rental bills on that server the website the application was entirely tied to the machine to the server it was on well with docker I can take this website and contain it in a container an image and that is essentially the whole application and I can redeployed this image on any other server and duplicate the website functionality so that's one great thing about it is portability the way docker is used is you have instructions indicating how to set up a server just the way you need it so I will always be able to know exactly how a server is set up as long as I'm creating the app the darker way like I might say that website requires a certain technology stack like you need sent OS version 7 my sequel version 5 PHP version 7 and python and the memcache version 2 and I can specify all that and that would say that the configuration files need to be done this certain way this is what the configuration files are going to look like and all of that can be contained in a certain container so it makes it clear exactly what are the configurations to get a website to work if it works for me it's going to work for you or anybody else and it gets rid of that world where I might have Python version 2.7 installed you have Python version 3 I copied the code over to your server and it doesn't work and then the last interesting that I think this off structurally for your coding is it really promotes the usage of microservices which is a recent trend so micro-services is the idea that you have many different services that each do a single task as you can imagine this would lend itself very well for scaling because you may have a chat server and that is a single service you can imagine if your program were to get very big you might want that contained on its own machine or even a group of clustered machines then you may not want another server for caching memcache or Redis you may want another server to do no js' only another server running maybe going for concurrent tasks or something like that then you have another server managing your message board now in reality most people aren't going to code this way because it's just too expensive to be provisioning new servers for every little service you want to offer what happens is you just install everything on one single machine and then this one single machine is overloaded with a bunch of random technology like it's got node golang Python PHP my sequel memcache Redis everything is all contained on this one single machine and then all the dependencies get mixed up maybe Redis is using Python version 2 and then you install golang and it's depending on python version 3 and you've just got everything all mixed up together and pretty soon you don't really know what you've got on the system anymore you don't know if your website is running Python version 2.7 or version 2.3 everything is a mess and furthermore you may find that sometimes you have certain services where you can only run a single instance of like for example a PHP web server usually does just a single version of PHP running it's not like you have version 5.6 of PHP running and then version 7 of PHP running on the same machine even though in reality you may have two different sections of code one is depending on the odd version once depending on the new version with docker and containerization you can actually create separate spaces for each of these services and that allows you to really separate out your program and think in that way - it lets you code in that manner and the great thing which get to the second reason this is so good is it scales very easily darker comes with a whole set of tools for deploying this across many clusters you can take your instances each service each micro service that you have in each container and then allocate many machines to them specify how many of the resources of each machine you want specify rules about how they should scale what should happen if they crash and it all scales up very nicely and makes everything scalable so that is what's so interesting about docker now what am i using docker for today well let me tell you what's going on for me I run the web server and it is about 10 years old and I'm using a fairly old version of PHP like PHP 5.6 or something and I needed a newer version of PHP to be able to interact with certain api's for a payment provider you know they wanted the newest technology and in order to accept payments I needed to use that and there was no way for me to use the newest version of PHP because I would have to upgrade my entire tech stack all the code would probably not compile correctly so what I have now is I have two web servers one web server is my main web server and then I have a second very lightweight paper use web server cost about 30 bucks a month for me and it is running the latest version of PHP I use that for the newer services that require the most recent in technology and what I realized was I can just use docker to run the latest version of PHP without necessarily messing up my other PHP stack so in this scenario I'm not using docker to scale program I'm using it to contain a subset of the code that I have so let's get into it the first step is to install docker which is essentially a command-line tool I'll be installing this for the cent OS a Linux distribution they have instructions for any other distribution though as well I am installing the Community Edition and yes I have installed it and the first step we can do that they tell us is we can just run docker run hello world and check that it is working and what this does is it will download the hello world container which is an image that pre-created and it will just run that code and we can see that it does work indeed my second step is to log into my current web server and copy all of the code over that I would like to reproduce on this new server so I've logged in and I can do the copies in either our sync or SCP I would just use SCP because this is a simple copy so I've copied everything over now and now we will create our docker container so I would do that by creating a docker file there are many different images that we can start with I'm going to be starting with the PHP Apache version and I'm going to build this now so I run docker build give it a name like my app and thought for the directory that I would use it's built and if I use docker images I can see the images that I have here I've actually created a few other images here but we can see my app is the one that I just built and I can even run it and we can see that it is actually order any it's booted up PHP and Apache and we can try to access this actually in order to access it you have to do some magic with the port and expose the porch correctly to expose the ports we will pass it an argument indicating that safe port 5,000 will map to port 80 for the application poor ad as a standard port used for web sites when I run this and then apart to try to access this website at Port 5,000 we're actually going to see that the website load and yeah actually it is loading but what we need is to specify the files the content for the website so we can do that using something called volumes which is pretty interesting in which you can map a directory in your current folder over for the container so that the container can access your files one interesting thing about containers actually is that they are generally supposed to be read-only such that they're not modifying anything and the reason is such that this can be deployed across many different instances and that are not really depending on the data that they have so I was specified that the public HTML folder should map to varda BW slash HTML in the container rerun this and if I were to read this website I can see that the website is now loading this is pretty nice we're starting to pass them a lot of parameters so I'm going to make a script called docker Rhonda SH which will encapsulate this command and so in this script I first stop dr. if I need to I filled it and then I run it I pass in - D - mean detached mode if I run the script now then I can see that it's running now and what if I want to login to the server well the way to do that is you run docker PS which shows the processes that you've got running so I find the container that I want to get into and I can login with bash and here I can just take a look see what's going on I can play around with and try to configure the environment one interesting thing is you don't have access to Emacs or any editors so it is kind of read-only and it forces you to kind of think about how are you going to edit the files using the set of darker route instructions you can go ahead and install Emacs if you want to do or vim but remember what we're trying to do here is not edit the files directly we want to encapsulate the edits in a set of rules in the docker file that way this can be replicated across any number of machines after some messing around this was the final docker file that I came up with and I'll go over it line by line for you we can see we're doing the image from PHP Apache I'm copying a HTTP configuration file for setting up Apache I'm gonna copy that over the default configuration same thing for PHP I'm going to set up the PHP file exactly how I want it and then run a few terminal commands using the double arrow operator which is for attending and now I append these configurations to the initiation file for PHP here the last part here I have is exposed to some ports this really isn't needed but it is self documentation sort of to indicate which ports that this docker file is going to need this container and one interesting theme that I ran into here was I figured out that PHP and docker does not really support send mail you can't really send mail out of it because the SMTP mail servers aren't really configured right and what you need to do is actually use another server so what I'm using here is s SMTP the server instructions here installs the container to install SSL TP and then copies over a configuration file for the password and authentication the configuration file I'm using an Amazon SES mail server to do the mailing and then the last part configures PHP to use SMTP and so what we have now is we have an additional web server running using the latest version of PHP and you know this whole time I've been running this other paper use lightweight web server it cost me 30 bucks a month and I can essentially now deallocate the server because I've copied it over to another web server which is actually running in the da Christ container and it's not messing up all of my other configurations essentially allows me to run multiple web servers with different configurations on the same machine that saves me some money so that's great if you have time it's also pretty fun to browse the docker repository you can see the images that are available and I'll give you a better understanding of what this can be used for you can see that my sequel actually has a verified official repository image for docker you've got Redis Oracle MongoDB Postgres Ubuntu node golang engines HTTP D which is Apache PHP Python and you've got a whole bunch of other things and this essentially allows you to try many different versions of say PHP Python my sequel without necessarily messing up your original machine configuration you can just isolate those changes within a certain container and if it doesn't work you can just trash that container delete it and it doesn't mess up your system from here the next step you could do is you could take this image deploy it across a cluster of machines have a load balance using say kubernetes or a docker swarm and scale that up across millions of machines and servers so there you have it that's a brief overview of talker and containerization for you but I would say that you don't necessarily want to jump into it too soon unless you see yourself needing it for a certain purpose like you want to isolate a micro service or you find yourself needing to scale a service more across multiple devices you know the funny thing is that web servers are very powerful these days and usually what's gonna be your bottleneck is still going to be your database server for various reasons people still don't quite recommend putting your database server in the da Christ container when the reason is that containers can crash the bottleneck is usually still that database server and you just want that to be as efficient as possible database servers also use persistent storage which makes it less easy to scale because every instance is still dependent on this one single storage anyway that'll do for me very interesting technology is something to definitely keep your eye on if you're studying for interview practice remember to check out algo expert the Iowa slash tech lead this is an excellent resource where they explain on video how to approach and complete many interview coding questions whiteboarding problems that you may encounter they cover data structures algorithms time space analysis for many different problems check them out I'd love to hear your guys's thoughts and usages of doctor and containerization if you liked the video give it a like and subscribe I'll see you next time
Info
Channel: TechLead
Views: 648,081
Rating: undefined out of 5
Keywords: images, google, engineer, kubernetes, devops, linux, containers, software, scalability, docker, containerization, web, coding, programming, virtual machine, scale, techlead, developer
Id: IbUXb4pQbPY
Channel Id: undefined
Length: 16min 27sec (987 seconds)
Published: Tue Jan 08 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.