Docker Tutorial part 1 | Python in Docker | Jupyter in Docker

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys it guy michael here and welcome to another video of our channel in this video i'm gonna show you how to run docker in your computer now this is a tutorial video it's a little bit different to the other videos on my channel which i published previously i want to do more tutorial docker like videos in this youtube channel maybe you know that i have couple of uh machine learning videos on the skillshare but i want to dedicate the youtube channel more to the docker development so if you are a fan of a docker development and stuff like this please consider subscribing to my channel now let's go to today's video so as i mentioned we're gonna download install and uh run docker on the mac uh in this video i'm gonna also show you how you can run python and jupyter notebook jupiter lap in your docker uh on your computer so now let's go to the video so first of all we need to download the docker desktop for mac so if you go to the docs.docker.com docker for mac slash install you can click the download button in the middle and in the top of the page so you can open it in the next tab and from the docker hub here you got two buttons one is stable and one is edge please click on the stable version because the edge version may contain some bugs so we don't want to take a survey so after a short time it's about 400 megabytes you will have the dmg file downloaded in your machine locally now you can click on this dmg file and it will guide you through the installation of the docker if you are using windows the steps are very similar there is a docker for desktop and the instructions are basically the same just by pressing next next next accept and waiting for the installation process you will have docker installed in your local computer so as you can see after clicking on the docker dmg file uh the screen like this will appear so you just need to grab the docker and put it into application now again this can take some time to install uh you don't see the progress it's here so it's unzipping the file decompressing it's about one and a half gigabytes in this case so uh if you are not sure or maybe the instruction change during the time there is always this manual page where you can scroll down and you can see what is happening where so so now you see that i put it into the application file so i need to go to the application so let's go to the finder we can open a new finder window and let's go to the application and there as you can see is the docker so now i will double click on the docker and it will launch the docker if you want to run the docker you can basically run it in every system with at least four gigabytes of ram of memory which is quite the standard in these years so there are much more stable and more powerful systems out there so as you can see docker is an application downloaded from the internet that you should want to open it let's click open now docker needs privileges access so you will be asked for your password so please give them the password now what is my password no so uh this can take some time until it will be run as you can see in the top right corner there is this docker icon and when the squares are popping up in the top it means it's still launching so you need to wait a little time sometimes on the windows for example you need to restart the computer also on some linux machines and maybe on some mac so we will see how it will behave in in the in case of my computer so as i mentioned in this video i'm gonna show you the step-by-step process of the docker i'm a machine learning devops engineer at the dell company and currently i'm doing this every day i'm working with docker every day so get started with docker in few easy steps there is some tutorial we want to skip this tutorial and if they are just showing you how you can run simple things but we don't need it right now so uh right now sorry uh so right now the docker is being installed and it's running so how you can uh like prove it is if you go to the terminal i have it open here i hope this is big enough for you uh if you go you need to open a new tab and run docker yes so as you can see if you are popped up with a top bar like this uh everything is okay if an error will be presented in this case it means that you have some issues during the installation and you need to reinstall it you can also run docker version i guess and it will pop up you the version the current version which i'm using is 190.12. if you are from future feel free to run the docker version you have right now just be up to date and have the latest version which is there on the internet so right now uh let's talk a little bit about docker so how looker works and why is the crew so powerful so i don't want to you know like overflow you with a lot of theory but basically uh the docker is solving one important issue imagine you have an application and you want to deploy it to some host machine when i'm talking about the host machine i refer to a server or some computer right so you have application let's say you have a simple python program and you want to put it onto different machine so what you need to do you need to install the python you need to install the libraries you need to set up the ports yes you need to set up the whole environment and this can take a lot of time and uh you need to run it on the system which is running on the machine so on the server so let's say you want to deploy it into the linux machine and you are developing in the windows machine so you need to go to the internet and and look for the manual how to do it on the linux machine and sometimes you are working with different distributions of the linux machine if you are using some dedicated server which you bought so for example you don't even know how to do it on this machine now uh docker is uh is a software which allows you to create a container now you can think about the container as a operating system as a separate operating system so within this container there is an operating system which is working with the hardware of the host machine so if you take your application you put it into a docker container which is running a dedicated system a dedicated operating system then you can take the container and put it into the whatever host you want and you can leverage the whole hardware of this host the biggest advantage is that you don't need to use the operating system of the host machine where you want to run the container now this is a big advantage why because you can run as many containers on the dedicated host machine as you want you can have the 300 containers in the same time and each can run different operating system one can be written in the windows server add one can be written in dbm other one can be written in centos and stuff like this yes so you don't need to uh like solve the issue of the incompatibility of this of your software with another system okay so uh maybe this was a little bit of uh you know too much knowledge for you but by the time as you will go through these examples you will understand better so the most important part is like the docker is taking the application putting them into uh the dedicated containers and then these containers can be deployed wherever they want so now many of you can say well okay but how can i you know run the dock locally so as i showed you you can install the docker as simple as this there are even manuals to run it in the linux machine but basically what happened right now after i installed this the docker installed two things on my computer one is something which is called the docker daemon so docker daemon is running in the background and is using my hardware so yeah in case of of mac os and windows it's a little bit different as i will talk right now but you will maybe go into these details later you don't need to bother about this the basic idea is like the docker demon is using the hardware of your machine right now and then there is something which is called docker client and when you want to interact with the docker client you are interacting with something which is called cli so command line interface so whenever i'm putting commands like docker version i'm interacting with the docker client the docker client is communicating directly with the docker daemon which is running in my computer so it's as simple as this so for example right now if you go out there and you buy a server somewhere yes you will have a server with at least four gigs of ram you will install their docker demon and you can run their everything which i will show you right now and even more which i will show in the future videos okay hope this wasn't so much complicated i won't do i don't want to put too much theoretical stuff in my videos but i have to because some of you maybe don't know document or are just beginners of the docker i highly recommend reading something about containers on the internet in the documentation down down there which i will link in the description below so let's jump right back into the video so what do we want to do is that we want to run a python in the docker right so as i mentioned we want to create a container with the python installed down there so the way how docker does it is that it takes some images something which is called image which is just a set of instructions and it runs them in the docker daemon so uh you need to find an image for the python in order to run a python in your computer now and many of you may say well okay but i don't know what's image i don't know how to create the image don't worry there are other guys who already created all the images for you so the only thing what you need to do is just go to the internet like this and go to the page which is called a docker hub so if you go like here and put the docker half there and you will click the first result it's called the docker app you need to sync up there feel free uh create account there it's very helpful we will use the it in the future video and then click here in the search bar and put here python now docker hub is something like a github okay many of you may don't unknow what is a github or stuff like this the idea is that you need the container to run an application in your docker in order to have a container you need an image which is creating the container in your docker demon now you want to share the image with the community this is the idea of docker in community in this case can be the whole world or your organization or just your family whatever in this case everything what's in the docker app is public everybody can use it for commercial commercial use if there is uh if there is no license and and you can use it in your code you can adjust it in your into your needs and stuff like this so whenever you go to the docker hub and you write everything we write into this search bar is for free and it's an image so as you can see when i put the python here i got a lot of results so there is a python uh image python is interpreted blah blah blah there is something which is called django image pi pi image a lot of images and now many of you may say well michelle so what is the best and as always there is something which is called stars which indicates how good is the given container and the number of downloads and the logic behind this is like the more downloads there are the more stars there are the more reliable the image is again i i highly recommend you to download only the official images at the beginnings in your beginner stage when you don't know what are you doing why because as i said the docker image and the docker container in your content in your computer will interact dialect directly with the hardware so this can bring some potential risks if some let's say hacker will create some uh container with the vulnerability which will you know put some virus into your computer this can be very bad but i'm just not talking about scary things most of the time nothing will happen because people are are good right so so but just to be sure always download the official images for example this python image is created by the python company this themself like the python group themselves so so if i click here on the image i will see that down there there is something which is called the simple tax or tax and here are all the python versions of the image available for you and now look at that look at the beauty three that nine wow treated nine the edge version of the python is there right three that ate that five three that's seven 3.5 even the older images are there if you scroll there sorry um my mouse is working differently 3.5.9 is the older version yes so so which version to use yeah you can choose the version whatever you want and now many of you may notice there are something some strange words like alpine uh slim stretch buster windows serocore the the the it's called the suffixes of the tags are referring to the system version so to the operating system upon the image was built so for example when you see here the windows server core so this is the python 3.7.9 which was built on the windows server so if you go uh here and you see there is a alpine this is alpine linux debian stretch the beyondbuster and and all the stuff now many of you may say okay michelle so it means that when i'm running a docker on the windows i need to use only the windows and here comes the beauty no you can run linux containers in your windows machine you can run a debian stretch based container in your mac yes so this is the freedom docker brings you freedom you can develop in every system in every operating system on every system which can run the docker of course so for the purpose of this example i'm going to use one of my favorite distributions out there which is a slim version uh the sling versions are are a sort of linux containers which are very small few megabytes and they don't have a lot of insight but they are useful for for developing because they are very fast so yes so so okay so right now we know that there are the images and right now we know that we want to run the containers locally with the image but we don't have the image right now here okay so uh we need to pull the image from the docker hub so uh how to pull the image from the docker app yes we're gonna pull the image the terminology is very similar to the github or the git terminology so in order to pull a image you need to write code as simple as docker rule and the name of the image which is the python and here you put the uh the column and the version so 3.8 dash sling right so by pressing these you will see that something which is called layers will be downloaded for you and the layers in docker like each of the uh image consists of few layers which are defining the image right now i will talk more more about the layers later right now you don't need to think about layers so as you can see i downloaded uh the docker client is saying downloaded the newer image from python 3.8 slim docker io library python 3.8 that's lame if you want to know what are the images locally in your machine you just go and go and write down docker image ls and you can see that we have the uh the repository which is called the python yes that's the name of the repository on the docker hub the tag the image id the created now the created refers to the date when the image was created uh in the docker app and the size you can see you just need only 130 megabytes to run a slim linux container with the whole operating system and the python installed inside there you don't need more than 113 megabytes so now we have the image in my local computer so how do we run it yes we want to run it okay so in order to run an image you go and and write down docker run as you can see it starts always with docker and and the keyboards are referring to the actual actions so docker run and now you can write down uh the specification of the image or you can use the image id yes so as you can see these image id some hash which is hard to remember so sometimes it's good to write down the whole thing like 3.8 uh slim so right now the docker client will look for the image in the local machine if the image is not presented there it will go to the docker hub and download it from there but because sorry but because the image is presented here it was run and as you can see nothing happened but why the answer for this is that the docker image python uh that 3.8 that's lame is basically doing nothing so the image was just run and terminated immediately yes so uh nothing was presented to us no output and and and we didn't even have the chance to interact with the with the image with the container so in order to make it like more like stable more interactive you need to run it with the tags or with the parameters to to run it in the detached mode and to trigger something which is called tti so i will explain what is tti right now so let's go and run so run it in detach mode is d and run it with the as a tti is like this and then you need to specify the name oh my god sorry you need to specify it like this python 3.8 slim enter yeah and so now something was outputted and it was immediately terminated again but this time trust me is running in the background so how how do i know it so in order to see what are the containers running in your machine you need to list them to see all the containers running in your machine you need to run the command i will first figure the the terminal so docker ps will show you what are the containers running in your machine and as you can see one image is running and beware this is container this is not image this is not the same output so as you can see it was created 25 seconds ago no ports whatever and the name is something like angry stone breaker right whoa what is this so when a container is being run on your local machine the content id will be assigned for it and also docker will create some fancy name for this i don't know they are creating the names sometimes it was based on some movie stars or some buoys this is just some you know some strange words i don't care so if you want right now when you will work with the docker uh container for for example with this container you can refer to the container with the docker id or with the angry stone barker blah blah blah right so uh if what we want to do now so we have the container running in our local machine and now we want to access the container and how you can access the container you can access something which is uh called the bash so we want to access the terminal of the container so how to do it so in order to access the container you go like docker exact dui because we want to access it uh with the tti and now the now here goes the the container at least so you can use the container id or the name of the container i will use the container id and now here comes the command which i want to run on the container so i want to access the patch and as you can see uh the command prompt changed so right now i'm in the container which is this one this is the same one and i'm there as root i'm in the root directory so when i go ls as you can see now there are different folders right so what is this michael i'm inside the container and and now i'm interacting interacting with the container so right now you can run the commands the same as they are in the linux in case of of this slim distribution so you can sudo apt-get install stuff like this if you don't know about this stuff don't worry i will cover something later in in later videos right now the thing which you need to know is that here will be the python installed so if i go here and go like python version you'll see magic python3.8.5 installed in the container i did nothing else just download 113 megabytes and install the docker amazing right you can go and and list the libraries and you will see that the basic standard libraries are installed here now well everyone is like well now you you can do everything in this container you can grow code from this container right that's true so for example let's go and install the jupiter up there peep install jupiter lap without the space it will take some time it will install it inside the container i'm not installing it to my computer i'm installing it inside the container it will take some time and uh after this has been installed you will see that the new library will be added to the installed uh libraries in the container yes all the dependencies listed here was installed so you will see much more libraries there list magic everything is installed right if you want to leave the container you just go and press ctrl d right so as you can see docker ps the container is still running here yes so if okay if you want to stop the container you go here and press and put docker stop and oh sorry i'm running it on the different keyboard as i'm used to so i will just miss clicks and keys sometimes so if you want to stop the running container you go for docker stop the name of the container it will take some time but after that the container will be terminated and you will see that in the docker ps now no container is running you can also run the container with uh with the name so for example i want i don't want here to have the angry stone breaker i want to have there's something fancy like name will be jupiter yes because we want to run the jupiter there so you can put here the parameter called name and the jupiters so if i run it like this and go docker ps you will see the jupiter is running here now but beware one fact whenever you terminate the container like this so when i go and stop the container which i created right now jewel fighter the containers are still existing in your machine in something which is called an exit state so i will clear it so even though i go like docker ps and it's not presented here if i go like docker psl you can see that these are the stone angry stone breaker is here the jupiter is still here what does it mean that even if you uh like cl uh uh sorry even if you like uh stop the container the container will be there so this helps the docker to cache the container when you want to run it multiple times one after another so what does it mean if i would like to run the jupiter right now with this command the same as as it was before i will be noticed with some error yeah error response from demon conflict the container name jupiter is already in use by container so what does it mean uh if you want to delete the whole container from your local machine you need to go like docker rm and the name of the container you python yes and now i can create it one more time uh with with this uh uh with this command now notice one thing uh if i will run again so right now i deleted the container created it again docker ps you can see it's still running if i go right now to the bash jubiter and the batch you will see if i go like fib list the libraries which i installed are from there are not there so now you can say well michelle this is not good i i want to you know to have uh the libraries there right you want to purchase the state and and this is like if when you understand when you will understand the philosophy of doctor this makes sense but at the first time this make note maybe it's confusing for you so let's let's jump right and install the jupiter lab again and i will show you what you need to do in order to persist the new updates into the into the container right now the libraries inside the container are system dependencies these are node data like files folders and stuff like this these are the binaries so if you want to have the container with the changes you create you need to create an image a new image from the existing container now please feel free to stop and think about this container is created from image now this container was created from image called python 3.8 i want to create a new container with from this updated image with the new libraries so how to do this so first pip list you can see that these are the libraries installed there i will terminate the container bash as you can see the container is still here so right now i want to create the new image from this container and you can do it with the command which is called docker comment the name of the image and uh and now you can create you can sorry the name of the container now you can create the image we will call it the jewel by turn uh the jupiter cast yeah uh it's good to put there the version so yeah uh let's stick with you by the custom so now when you run these this will create a image called jupyter custom in your local local machine so if you go and well i will clear the window so if you go like image image ls you will see the jupiter custom is now presented here so you can see that the container is still running here so first let's terminate the the the container docker stop jupiter yes this will take some time it will stop the container now don't forget to remove the container because the exited container is still running there so docker rmg biker right and now let's run the container from the new image which i created the jupiter custom now uh we can do it like the same way as we did before so python slim and instead of python slim i will put here to fighter custom because this is uh image name and uh to make make things more like easy uh because when so so right now when i stopped the container i always need to remove the container with the rm but you can put a parameter called rm here and what will these do is whenever you will close the container it will automatically remove the exited container from your local machine so if you run it like this so rmdt name you pythopiter custom and press enter the container will be created dr ps yes and as you can see if i go into the oh wrong key into the bash sorry i'm so sorry darker exact t-y this time we will use the id bash and now if you feel like people's wow magic all the python libraries are there persisting right so whenever you will create an update with the libraries with the system dependencies of the container you need to create a new image from the container in order to be able to work with this so right now what we want to do is to uh run the jupiter inside there so uh the basic command to run the jupiter everywhere is like jupiter lap right but uh if you have been using the jupiter before you know that whenever you put the jupiter lab command inside your terminal it will immediately open your browser this is a little different because the container doesn't have access to your browser and it cannot open anything from itself so so you need to run the jupyter lab in a very special way right so i will explain so we will run the jupiter with a few parameters one of the parameters is the specific ip address which we want to run the jupiter on in this case we want to run it on 0.0.0 which is the localhost of the container and we want to run it on the port uh 8888 now many of you maybe don't know anything about the networking in general uh the thing is like if you know what is networking that uh then the docker demon has its own network and its own ip space and basically the container can access uh its on localhost by specifying it so the same localhost is in the container as it's in the normal computer and you can specify the port there you can use the whole range of ports in the docker and the docker dn will map the ports in the very specific ports in the host machine right so working with the ports and the ip addresses it's quite tricky and i will dedicate there some future video but right now for those of you who are only interested in the basic parts uh if you want to run the jupyter lab you need to specify the ip address of the localhost you specify the board you can put there whatever board you want highly recommend 888 then there will be no conflict and we want to run it without the browser so no browser browser and we want to run it like aloe root because this is the default way well the default of the jupiter lab is allo root falls but we want to be able to run the jupiter lap as a root also so when you run it like this you can see that you have this beautiful screen which is always telling you that the jupiter is running yes and what most of you will do right now is just they will go to the chrome open it and go to localhost 888 and nothing right now why so you need to understand that the container is a separated space so a separated system which doesn't which is not communicating with your local system right so whatever you run in the container is not available outside of the container if you don't say so right i didn't specify something like okay guy please uh you know run uh the port 888 from the container in my port right and this is exactly what i will do right now so you need to create a connection between uh the so between the uh local machine and the container between the ports of the container and the ports of the local machine this is what we're gonna do so in order to do that you need to terminate the jupiter ctrl c yes uh ctrl d now docker ps still this is running clear let's stop it docker stop jupiter now uh we will use the same run command but we will specify some more parameters there so the parameter which we gonna specify is uh the port which we want to map to the port of the local machine so let's go ctrl r and run search for run and here it is docker run rm so because i run it with the rm this is just a fun fact if you go like docker psa you will see that there is no jupiter uh container right because i run it with the rm so this is just the proof for you so let's go clear run so i have here docker run rmdt because you know i mentioned it before and now i want to specify the port from the container to be mapped to the port of the local machine and to do it is as simple as sport eight 888 eight eight now the second 888 refers to the port in the container and the first eight eight eight eight refers to the port in the local machine so right now everything what will be forwarded to the port of the container eight eight eight will be uh forwarded to the boarding local machine 80 day date right simple as this running this will create the content sorry we'll create the container docker ps blah blah blah now docker exec t y uh jupiter bash ah by the time you learn these commands by heart if you are not able to remember these commands don't worry i will link in the description the github of me with the uh all the commands which i'm using right now so feel free to copy paste it from there i don't recommend doing that you will learn more when you will rewrite it on your own even just by looking at the video and rewriting it one by one will help you more than just copy pasting it from my github but i provide it there if you will stack and you don't know why you can just always go there and and download the the file so i'm in the container it list and now i will do the same thing so is it in the history oh no it's not so i need to read it you fighter lab uh so ip address is set to 0.0.0.0 uh the board is set to 8888 and uh no browser and the allo the root right so i don't want to rewrite it all over again i will copy copy it and put it let's say somewhere here right right so running it everything is okay if i go here ta-da everything is okay it's asking us for the token for those of you who know something about the security in jupiter you know that the jew partner provides you a token you can find the token here in the url address there is a token you just can copy it from there by ctrl c command c on the mac create a password let's say whatever and this will open at the jupiter lab for you wow amazing right you are running the jupiter in the container right now you what you can do is just you can take this container put it everywhere in every machine and and be able to work with it so yeah whatever we don't save the password the next thing which i want to show you is how you can map a folder from your local machine into the container so as you can see these folders here are the folders of the container yes but sometimes you want to access the folder in your finder right you want to map the folder from your mac machine or windows machine or linux machine whatever into the container and this can be sometimes trickier so how we gonna do it yes so as i said containers are separated environment they don't have nothing common in common with the local machine right but you can create bridges for example i create a bridge between ports with the p variable by running the docker run so how you can specify the volume or how you can specify the bridge between the file system of the local machine and the container right so we will go back to the terminal and we will terminate by control c control d now docker ps we have still here the running container uh we need to terminate it so docker stop ctrl v right so uh let's just create a folder for this purpose okay because you need to have this source which we want to map to the container so right now i'm in here going to documents ls and i will create a directory called docker docker tutorial tutorial cd docker tutorial clear okay dvd i'm in my docker tutorial so right now i want to map these folder into the folder of the container to do it you need to run a simple commands as so let's go back to the run command oh run and now i will put there some magic so if you want to link the folders between the container and local machine you will use a parameter called mount so mount uh and now you are specifying the source so this is the source in your local machine and oh sorry source and you will we will specify the source with the pvd command in the sub shell so for those of you who don't know anything about shell and base and stuff like this this is just calling the pvd the same command so it's it's just returning the path to the folder in the local machine and we will map it into the target of and now you specify the name of the folder inside the container and we can call it up yeah so by running this so sorry guys i was like debugging why it was not working and i found out that i'm i made a very silly mistake so if you want to bind the volume so besides just specifying the src uh and the target you need to specify the type we just said to bind i i totally forgot about that so so i'm sorry so this is the whole command in the docker client which you should run in order to bind the volume from your local machine into the container so by running this i go to docker ps i can still see that the container id image command python created two seconds ago status uh up two seconds ago you can see that i i am mapping the ports uh with the type of tcp and the jupiter is the name so right now i can go again docker exec ty uh the jupiter and bash so a bit list and i can still see that these these are the things and i forgot the command so i need to rewrite it new fighter lab uh then there is the ip equals to zero that's zero that's zero that's zero and then there is the board equals to eight eight and then there is the uh no bro browser browser and allow root enter good oh sorry what i forgot so right now well after i map it you can see that the app uh folder appeared here so if i go to the app and press ls nothing is there so right now in my local machine here i will go to the folder uh docker tutorial and create here some new folder let's call it test right and as you can see after creating here the test the test will immediately appear in the container how cool is that right so you can run the jupiter from here and i will show you one more thing so one more time thanks for the history that's the most useful feature of the linux so right now i can go back to the localhost i will be asked for the password again whenever you run it for the first time after stopping and running the container again you will be asked for the password uh copy create some password you can put there in the second row whatever password you want it doesn't matter so as you can see the test is here and when i will create the notebook here it will immediately appear in my local machine wow so this is just the basics of of the jupiter and i also showed you how to bind the the file system from your local machine into the docker now this can be very beneficial for you because i'm a data scientist and i'm using jupiter daily and many times i need a fast development environment wherever i go simple to trigger simple to install things and many times i need a separated environment variable for different projects so having different libraries having different files for different project without which i'm working on docker gives you the opportunity to separate it right you can have your own container for this encoder for that you can have different versions of python there and stuff like this so i highly recommend you to try this out uh you can try to run the two fighter from there map the volumes right uh run some tests uh you will see it's as fast as you as if you're running it in your local machine so guys that was everything for today i hope you enjoyed this video uh i would like to create more videos like this if you will reach at least 100 subscribers and some likes i will create another another hands-on docker tutorial video so i hope you enjoyed it my name is uh i think michael uh please consider liking me on the facebook and i hope i will see you in the next video thank you very much
Info
Channel: ItGuyMichal
Views: 19,370
Rating: undefined out of 5
Keywords: docker tutorial, what is docker, docker container, python in docker, ItGuyMichal, IT guy Michal, docker tutorial 2020, docker hub, jupyter in docker, jupyter lab in docker, python tutorial, jupyter tutorial, devops tutorial, docker step by step, step by step tutorial, docker image, docker on mac, docker tutorial for mac, docker for macbook, install docker, how to install docker, how to docker, what is container, what is image, how to start with docker, dockerization
Id: At5alroIsic
Channel Id: undefined
Length: 45min 47sec (2747 seconds)
Published: Sun Aug 23 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.