Learn Docker in 20 Minutes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] cut everything hi I'm Thomas a full stack web developer and in this series of videos I'm going to be showing you how to implement docker into your development workflow docker has many uses but for the purpose of this tutorial I'm going to be showing you how to host your local files on a Linux virtual machine this means no more headaches when you're trying to transfer your project from Windows to Linux you'll be able to develop with your destination platform as a first-class citizen let's get started in order to install docker you're going to need to go to dr. calm you're going to click on get started so it's going to take you to docker for Windows and you're going to need Microsoft Windows 10 professional or Enterprise 64-bit you're also going to need a Intel CPU that supports virtualization so you're going to have to do some research and figure out if your CPU supports virtualization and more specifically if it supports hyper-v so you're going to download and get on to installing docker so the install process is actually fairly simple you just click install go through the prompts and there you go it should finish relatively quickly now I'm going to go over some more advanced things that docker does so you can get a general grasp of what it's used for the number one benefit of using docker is the fact that you can easily configure environments and share them on any platform now environments don't just have to be like node or Python or a bun - just something simple with docker specializes in is actually massive horizontal scaling each environment can be composed of many many different containers and each container would be say a node.js instance or a Postgres database or a reddit store or an engine X front and as your system requires more and more resources docker will spawn instances of what it needs in order to provide the resources necessary that's all I'm going to say about this for now but if you are interested in seeing what docker is capable of I highly recommend you checking out their site and looking through it so now that doctor has finished installing we're just going to launch docker if you happen to be running darker on a virtual machine like I'm doing here you so now docker is up and running where you see your little prompt it's going to ask you to test some of the commands and do whatever you want to do so if you want to follow the prompt and do some of this you can but I'm just going to skip past that we're just going to open up Windows PowerShell we're going to do a simple hello world so with docker let's just quickly check to the version so dr. - V and there you go you get our version mine's 1.13 you might be on a newer build actually very simple we just type docker run hello - world now docker is going to automatically detect that you don't have the hello world image on your computer unless you do for some odd reason but if you don't have an image docker will automatically download it and voila there we go it's already done hello from dr. this message shows that your application appears to be working correctly and that's all you need to do in order to run hello world okay so now we're going to do something a little bit more crazy which is getting bash running in right here on the Windows PowerShell terminal and in order to do that we're going to enter the same command docker run but pass it an IT argument so - IT and then you're going to right move on - which I'm horrible at doing apparently but I'm going to show you exactly what IT is before we run that so you're going to do - - health in order to get a list of all the possible arguments and here - I which is interactive so it's going to open an interactive shell and then T which is going to make a sweet o terminal which is basically like when you ssh into a server or something so in order to do this now we're just going to do docker run - IT bun - and it's going to automatically install the Ubuntu container which is not an exact replica of what would normally ship with a bun - like you're not going to get vim and like the Nano text editor because these are these are scaled down very small so they're performing and all that like not going to waste a lot of space on your machine as you can see it's only 50 megabytes which the ones who's pretty small already as is compared to released Windows but 50 megabytes is ludicrously tiny ok so now we are in the shell we are in Ubuntu so in order to prove that you could just type LS which is going to list all the items in your working directory and voila everything you would expect from an Ubuntu install ok so now let me go over some of the things that are you know quality of life and things you need to know for the shell when you're running docker with a bun - so when you create a container you're going to want to give it a name in order to do so you just do - - name and then pass in whatever name you want in most cases you're going to want to give you a container a name about what it does or what it posts and why log where in the shell so the reason for naming this is because in order to exit the shell you have two options control PQ which will return you to where you are but continue to run the Ubuntu image and so you can type docker PS to view your available containers and here we have a container ID image command created in the name right here which is James and in order to get back into our Ubuntu container or Ubuntu shell we just write docker attached dames so enter the container ID now see here how it looks like it's paused it's just because you have to add some kind of input in order for it to register I don't know why it does that but it's just a tiny bug that they still haven't got around to fixing now another way to exit is to literally just type exit in the shell which is going to close the container the container will not be running anymore so if we write dr. PS you can see that it's missing it's not there now another thing you can do is docker images which is going to show you all your downloaded images and as you can see here we have run through in a hello world right now we don't need hello world so you can type docker remove I like RMI which does remove image and we just type hello - world now if it doesn't work you just do remove and you pass it a force variable okay and voila it's gone so now we write docker images and all we have is Ubuntu now so let's clear the screen and show you one last thing so say I have my eye doctor shell and I use control P Q in order to exit it and I still have my shell open my container is still running say I want to remove it without entering it I would just run docker RM dash F the force variable to make sure you know gets rid of it and then docker assigns random names if you don't name your container so this one is called clever Shannon so let's just remove clever Shannon and there we go and now if we run docker PS no more clever Shannon okay now that we have a basic grasp on how to use docker and what it does let's move on to implementing it into our development workflow because that's the fastest way to learn so I've gone ahead and created a github repository here with some little system little stuff all it does it's just a simple nodejs application that prints the node environment and it prints the environment that the file is being served from so if it's running on Linux it's going to print Linux if it's running on Windows it's going to print when it's running on Mac it's going to print some crazy stuff so let me put the URLs down here at the bottom and let me copy this and we're just going to do a git loan well guess what clone it into HS and there we go now we're going to navigate to docker hub so hub docker comm and we're going to look up the node package because this is a node file this is a node application that we're going to be serving go to the node package we scroll down until we come to here we're going to create our own docker file so I'm going to open up sublime text and I'm going to ash these to the sides we're going to copy right here what they have pasted here to remove this so we have from note so what trum means in a docker file is what is it going to base itself off of what images are going to use to create itself say I wanted to create an Ubuntu application I would be replacing this with Ubuntu now note actually has its own from move on to like it's on an Ubuntu server itself and then we have exposed here which is going to expose the port that our application is running on now the application I have made is running on port 80 I chose port 80 because that's the standard port when it comes to hosting a website off of a server and you're not able to do it on your host PC typically begins the protected port now I'm going to save this docker file into the directory that I cloned my repo into now this is very important you need to make sure it's called dot dr. file same casing because this is the file that docker will be looking for and this is literally the file type is docker file these save and there we go we have it finished now we're done with this we move over here back into our terminal and put this to the side actually now let's get around to actually building our application so what's CD into our repo and let's quickly just open that up for me to explain we need to have our application our docker file in here and the application together because it's going to build this application in this repo it's going to be looking for it relative to its position so it has to be in here and they provide us with the command to build our applications let's copy-paste that now docker build - tea now - tea means tag is what you're going to be naming your image so in my case I'm going to be naming this hello system and then got this dot here which is you know the relative file path so is this is where it's going to be searching to build the application and in my case this does not work so I have to add another argument which is dash F so file because we're going to going to be telling it what file to look for so in my case is going to be looking for a dot docker file and then we have to put in of course the relative path again and now it will start building now I have no idea why it does this on my machine of course I am running this all off of a virtual machine so there's a lot of problems here but you know you got to learn to adapt okay so our build is finished and now we can move on to the next step which is actually running our application so they provide us with the command to do so and don't worry I'll go through with each of these arguments mean and here we are so basically what this is going to do is it's going to run the application and it's going to do the - I - just like you would run with a the Ubuntu because it is Ubuntu and so - I interactive - T TTY a suede o terminal - - R M now what this does is every time you start the app it's going to start fresh it's going to delete everything it had before and basically just boot from what it came with and then here - - name we've already gone through which is my running app and then my no js' - app and we could just run this now but of course we have to replace that with our image name which is hello system and voila here we are it's running so in order to access this we're actually not going to be able to get to this through our localhost right now if I go to localhost 80 of course it's not going to work want to access our application that's being served on the containers port in this case it's a tea and bind it to whatever port we want on our local machine we're going to actually have to add a port command so let's just do that real quick so - P and then our port this is the port that we're going to bind it to so in my case you know let's just go a little crazy here with 1337 and then add in the containers port this is what the application is being served on so in our case it's port 80 and then we can just pass the name so let's call it high and then pass it the image hello system it's going to run here we are and we come here to localhost and it's going to greet us with hello Linux which is what is being served off of now say we want to make some changes to the file and let's just go ahead and do that real quick let me show you the problem with actually changing the file right now and it's not going to work so let's go in here let's edit this and here we have hello and let's just change this to hello there buddy and then it's going to say whatever now changed but the problem is even if we run the same command ah now if you went into this error you actually have to remove the you have to remove the container even if it stopped like it won't show up here in dr. PS but it still exists like I can actually just run doctor's start and I believe I can just leave out all of the arguments and your undock starts hi and it should just start whatever I had and it's actually going to start it in a detached mode if I wanted to start it attached I would of course passed the IP parameter but in this case it's detached here we are we can just come over here and it's running right now as you can see it's running if I wanted to get back into that I could just docker attach myself to hi and here we are we're in it it doesn't show anything of course nothing is being logged to the console so let's just cancel it close it and now in order to remove this from it we're just going to have to do exactly as I've shown previously which is docker remove - force hi and remove it from the system now we are able to re execute the command and the changes you're going to see have not been made the changes aren't here so in order to get these changes pushed to our application we're actually going to have to think like our file system to the containers file system now we could just constantly rebuilding applications every time we made a change but that is a hassle and that takes a lot of time so to avoid said hassle we're just going to bind our file system to the Linux file system in order to do that you're actually going to have to come down here to the little rail go to settings go to shared drives and select your your drive that you're serving the application whatever file you want to bind you have to that whatever Drive it's on you have to share it so now we just run docker run it P 1337 80 and just to show that I can make this port whatever whatever I want let's change it back to 3000 here and then - feet now on windows you can't do this okay you can't name your file something like that like a C or something you have to do it this way the Linux way you would do - - the slash users slash whatever you are wherever the file is in this case for me it's in the HS folder and then we're going to find this - in this case on the node thing it's going to bind your app like your app is going to be located at user slash source slash app and then let's give it the name again the name hi and then hello - system here we are 13:37 anymore and with wala there are are changes now this can actually be done live anything with images anything that's not that it doesn't have to be recompiled by note every time you do it like static images or like ugh template files like HTML files but you know it services and stuff it could just be done live you can just change it keep the thing running and you don't have to restart it every time you edit the files in this case though because the server is running on this I have to restart it every time I make a change now I'm going to show you how I use docker to support my development workflow so here we have my portfolio website directory and here's the docker file exactly the same from the previous parts of the tutorial now in order to actually start working with docker of course you need to run it so doctor and I'm going to check my images to see what I've got here you see I have my portfolio so I just do dr. run - i.t portfolio but let's not forget we need to include our P so in this case 3080 because it's being my application is being served on port 80 let me just show that right here port 80 we also need to sync up the libraries and there we go the libraries and now all we need to do is run this and there we are my website is running so let's take a look and voila my website is currently being hosted on docker you so now let's just show a little bit of that live file changing that I mentioned so in that case if I go over here to my views and then into my index because the directories are synced using docker volumes I can just do whatever I want here say I want to add an h1 so this is using the pug templating engine so h1 doctor is here save and now all I need to do is refresh and there it is pretty cool right so that's the basics of what you need to get started with implementing docker into your development workflow my name is Tomas and it's been a pleasure thanks for watching hey guys thanks for watching the video if you're interested in coding bootcamp check out dev Mountain comm where housing is included in your price of tuition and don't forget to Like comment subscribe and share and support me on patreon I'll see you guys the next video thanks for watching
Info
Channel: Dylan Israel
Views: 534,861
Rating: 4.7707763 out of 5
Keywords: Programming, Coding, Software, Learn to Code, Learn, Tutorials, Course, Classes, CodingTutorials360, coding, tutorials, 360, walk, through, walkthrough, podcast, interviews, developer, learn docker in 20 minutes, docker, docker tutorial, docker (software), docker container tutorial, docker container, web development, docker guide
Id: wCTTHhehJbU
Channel Id: undefined
Length: 20min 28sec (1228 seconds)
Published: Wed Feb 22 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.