From Zero to Docker - Tutorial for Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys Johnny back with another tutorial this time from zero to docker know since you clicked on that video I already assume that you know what docker is however since this tutorial starts from zero here are some key aspects developers use docker to eliminate the verse on my machine problems when working on code together with co-workers operators use docker to run and manage apps side by side in isolated containers to get better compute density and enterprises use docker to build agile software delivery pipelines to ship new features faster more securely and of confidence for both Linux and Windows software now give me 30 seconds of theory I think you'll thank me later Dockers definitions of isolated operating systems are stored as image files they are basically a cooking recipe for things like install Ubuntu and then install Apache of course this can get as complicated as you like instances of images are called containers they are the objects you'll deal with most compared to object and object oriented programming your images are your claws and your containers are your objects or you can compare it to containers on a ship from the outside they have a unibody but inside they can look very different container is usually communicate with each other like real computers in a network so usually the tcp/ip containers however are not persistent that means whatever you do inside containers is not persistent when you start the container next time that's what images are for however to make data persistent you might want to use volumes volume are underlying data layer that you can use for multiple containers last but not least you have networks that wrap a whole bunch of containers now since we start from zero this begins with the download of docker so we have here our black map and all you need to do is to go on this website and as you see here you have all the different versions already so this is a map we download the community editions for Mac and we just need to wait until it download it all right it's downloaded so just execute the dr. dmg on a Mac and drag and drop the docker dot app into your applications it's as easy as that now we can use spotlight to execute the darker app and of course it's going to ask you if you want to open this application this is only being asked for the first time then click Next here and click OK here it just needs your password type your password here and then all you have to do is to wait but this doesn't take very long you already see the little darker symbol in the menu bar and the Dockers darling right now all right so docker started it's up and running and you're basically ready to go from here on just open up a terminal and to check whether everything went correct just type docker - - version and hit enter and if the version appears here you're ready to go to the next step however before we go to the next step let's just really quick way for our Linux colleagues and let's install docker on Linux as well so all I did is hosting a Ubuntu virtual machine on digital ocean which is fairly easy so as you can see here I'm locked into my machine if you're going to 16.04 and all you need to do is execute all the commands that docker needs and that's actually a pretty good tutorial on that on digital ocean I'm going to link this in the description so all you need to do is copy and paste these four commands into your command line this is what I'm doing right here so first you need to at the darker repository then apt-get update a man sudo apt-get install - why docker Community Edition all right this is it so now you just have to type dr. Rajan hyung so here's your doctor version and you're ready to go all right let's get started with some real doctoring so I have right here the guide written how-to docker I wrote it and I have the link in the description it's hosted on my github so as you can see here it's the same theory that we already read through but it also has all the commands that we are going to execute now all right so just open up a new console window and type the first command docker run hello - world all time programmers favorite and is executing already so what you can see you right here it's trying to look for the hello world image locally but it doesn't find it of course we have never done something of docker so what is doing it's pulling the latest containers from the official docker hub repository the download is pretty quick and here's the output of the container so as you can see here to tell you right away what it has done so first of all the doctor client contacted to the docker demon then the doctor daemon pulls the Halliwell image from the docker hub then the doctor daemon created a new container from the image that was in the cloud that you downloaded and now it's being executed then the doctor daemon stream that output to the doc client which is your computer right here and this is what you see in your terminal right now however now we are not inside a container as you can see here with this little squiggly line we are on our host system which is my Mac in this case so now let's execute this command docker PS - a and the output of this command is all the running and exited docker containers so as you can see here we have wonderful container from the image hello - world exited 46 seconds ago it has an ID and a name the name is just randomly generated you can refer to darker containers with both names and ID now let's start a docker container with our own custom names so we don't need to rely on a randomly generated name and this is done with the - - name flag so of course it has done the exact same thing however if we run docker PS - hey now you'll see two containers one with our custom name my - hello now let's do a little bit more elaborated container command again we will use the - - name flag also the - IT flag for interactive TTY and then we want to use the image you burn - and directly jump into the - again it doesn't find Ubuntu locally so that's why downloading ubuntu it's doubling the full you're going to container now as you can see here and as that is going to take a while we're going back to our browser and I'm showing you the docker hub on which you can find all the public repositories so that's basically a github for docker so here you see the Ubuntu docker image it already has 10 million plus copes so that's how you see how popular it is and that's basically whether your computer is downloading from right now so after your wise it has finished and now you see this little hash right there that you're inside the container so you're actually brewed at a FB and so on which indicates that you're inside your container now and you can basically execute all linux commands now so for example a list directory this is how it looks like inside container but now let's exit this container again and we run the doctor PFF a command and of course now you see here three containers all exited so no container is running right now and all the name partly custom partly random now what's also interesting is the command docker images that just lists all the images that you have offline on your computer now so download the hello world image first and now you downloaded the Ubuntu image so this is now offline on your computer and you see the size right here but now let's rerun the Ubuntu container just with a new name because it can't overwrite the old container and let's see boom it's right there after second this is because your image is already downloaded so basically you can start a ubuntu running environment on your computer in one second from now on since we already have now a couple of containers that we started we might want to delete this list cuz this list would keep growing if we wouldn't believe it and you can actually type this command is also in the tutorial that that link dr RM with the output of all exited containers so if you run this command and then rerun the PS - add a command you'll see that no container is running anymore but still of course you have your images you're going to and the hello world one on your computer next thing we want to do is start a container where we link local data inside the container called a volume we do that with them - be flag so just be type the exact same command as earlier we again need a interactive container so that we are inside the container as soon as it started we want the name again my Linux container we want the remove flag that just does automatically what gets done manually earlier so it removes your container after the exodus and then we need the - V flag and you actually need a full path to your local folder and then you separate it with a colon and let the path inside the container and then again you're going to and Bosch to start the container and if you list directly inside the container you now see the my data folder here so if you CD into my data and this directory again you see all the content in this container which are actually on your host operating system that's pretty cool cuz you can use code inside the container done now since we learned how to run images from the official docker repository we want to create our own image that's what we are going to do right now what you need for that is a file system and then maybe a text editor because what you need is a file called docker file with a capital D inside the stalker file you need keywords that tell docker what to do there's actually a full list of keywords that I'm going to link in the description down below basically every container that you built is built upon other containers so you all always start from a public container like let's say you're going to container again so what we need for that is the from keyboard so from Ubuntu we want to build our own container and we just add one command here the CMD key word is just there for a command that you want to execute and we want to execute echo hello and you can just type your name there in my case that's hello Johnny that's our doctor file for now so that's pretty easy now we need to change into this directory my container tutorial and if you lift files right now we see this docker file of a capital D so what we need to do is build this container that's done with the build command docker build - P this is the tag to give you the name we call it my Ubuntu image and then you need the dock the dot is there to refer to the docker file that is inside this container now if you hit enter it's going to build image and as you see here it has the steps that you have in your docker file now if you type docker images you have here a list of three images by now including your own one called mine you go to image called that's how we called it in the tags and of course we want to run our own image so just type docker run my you going to image it's referring to the image list that you execute it earlier and of course all it does is the echo command that we have inside so just help me hello Johnny exits right away and I'm back in my house operating system so if I now type docker PS - AI again have the full list of my running containers of course I deleted the earlier running one so right now I just have this one my Ubuntu image because I called it my you going to image with a random generated name and of course a random ID now we want to do a little bit more elaborated docker file let's say we have the use case that we want a Ubuntu image with Python pre-installed what we need for that is instead of the echo command just be run apt-get upgrade and apt-get update and apt-get install - python free now the question is why would I use the end instead of just the newline which I also could do but docker built a new container inside for every line in your docker file that's done because of the caching so that you can research your paint containers without the need to wait and to combine multiple commands in one you can just combine them with and this is just a standard Linux command now of course we need to rebuild this image because we changed the docker file so we can just reuse the old command and as you see here it's now building the container all right we are back in our host system now let's run docker run - GT my Ubuntu image and boom right away it started and you can type Python here actually I think it - 3 and here there you go now you have a ubuntu image with python pre-installed you can do all your typing commands in here alright so this is it I think with all this information when you are good to go - give it a first shot and fire out your own docker container just download the software and play a hat you can copy and paste all the commands that I've done in this video what's the tutorial I'll link in the description below thanks for watching
Info
Channel: Jonny Langefeld
Views: 399,517
Rating: 4.8243904 out of 5
Keywords: tutorial, how-to, diy, docker, programming, linux, computer, science, learn, data, programmer, terminal, command line, developer
Id: JprTjTViaEA
Channel Id: undefined
Length: 16min 0sec (960 seconds)
Published: Sat Jun 17 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.