Hi everyone.
Welcome back.
So in this video we're going to finally jump into docker and see how to use it especially on our application
right now.
So if you look at our application right now if you go to that stuff and tutorial one and it's only just
one file app Abdon Dhabi which just has all the logic for the server and you know we now want to start
to change this system into a docker crisis.
Now first of all let's open our system or actually let's leave that till the end and see how you organize
our product first and then see what the requirements are.
Now the first website I want to introduce to you two is Dr. shop and Dogger hub is a place like get
a job as the name might suggest where people store a bunch of darker images that describe different
systems.
So for example if a wall or looking to search for a license anywhere we want a system that has bison.
If we just search for a system that has by then you'll notice here that there is an official image off
by then and I can choose that image up by then so here I click on that and more details.
And so you'll notice here that we have a daquiri image.
And so later on when we're writing the docker file you're going to notice that I'm pulling right away
from my.
And if you're wondering where this is pulling from this is actually where it's falling from.
So there's so many different versions of Python the doctor supports or the official version at least
and you can install any of these.
So we're actually going to be using version number three.
So I just wanted to show you where we are because when we're writing the docker file We're going to
be using from Python's street.
And then you might be wondering well where is he getting this from.
And the answer is from this doctor hub the software ocker itself knows how to get the doctor from from
this place over here from this doctor hub and downloaded onto your local machine without you needing
to do anything.
Now that's you for a doctor out now.
The second thing is we want to start using darker and darker compose.
OK.
So we're going to click on tutorial one and we go in.
And so the first thing the way we're going to be organizing this project is we this this app that DeWyze
actually the web server.
So I'm going to make a new folder here so it's not allowing me.
So up close this and open it again maybe desktop tutorial one.
No.
OK let's try with the termino.
So it's probably just permissions problem so let's go to desktop and then tutorial one.
And so once we're inside we can make a directory and we'll call this directory with.
OK.
So this is where we're going to copy or put all our web application related stuff there.
And so we do.
So that's the.
OK.
So if you're not sure what to do.
Bang bang this is this basically means do the previous operate or command that I just did using sudo.
So it's basically sudo and then just copy this command over here.
So it's much faster than just having to write everything from scratch.
OK so if I have another for if I have for example a database then I would do so to make directory and
then I would make a directory for example such as database D-B.
OK.
So for every different container that you're going to have you have to make a new or folder to store
all the related files to that.
So since we don't have that database for now we're just going to go into web.
OK.
So once we're inside with what we want to do a couple of things we actually want to copy right so we
want Capuzzo to Suder copy and then we want to copy the file from the previous one is called IPY.
And then I want to copy it here.
OK.
So once I've copied my file as I do L.A. and I saw my file you're now Dockery expects to see a file
called docker.
So I'm going to do touch her file and I'm going to explain to you what this is.
In a moment so Ducker always expects in one of these folders to have a file called Doc or file.
OK.
And it has to be spelled in this way and doesn't have any extensions.
OK so you just do touch and then dodgier file.
OK so again you don't.
And now if you do it.
LS We have two files we have added up UI and the knocker file.
Now if you remember in the first few videos are we installed a flask and we installed a flask restful.
Right.
But now we want to tell you that there are some requirements for this web application to run.
Right.
So there are some dependencies.
And so we have to touch requirements requirements that TXI.
And then in this requirements the next year we're going to store all basically all the different libraries
that we need like flask and flask restful.
OK and pseudo again keep her from forgetting it.
And so if we do ls now we have an app that p y.
This is the original application that we wrote and then we have the Dogger file.
And we have that without any extensions and then we have requirements that 60.
Now if we open our sudo at home here.
So let's open an atom in this folder over here to do C and then the first thing is we have free files
right at that p y.
So add up us the same file that we wrote and if you notice you're using flask and flask cresc.
And then Dharker file is just an empty file and requirements XTi.
Right.
OK.
So let's first just jump into dog or file and explain line by line so we're going to read a couple of
lines.
I think we're going to write like five or six lines so it shouldn't be too big and we're going to explain
what each of these lines does in in this what once it starts.
OK so the first thing is we're going to write and write from by then.
So Python 3.
So I'm pulling from Python 3.
So where does this pull from.
Well it pulls from the Web site and I just showed you so it's pulls from the sphere.
This official repository.
So I just do pull from Python 3 so it downloads I three.
OK so once I have this by three actually what you don't know is that the Spice's 3 over here is not
only bytes in but it has a buntu image on top with it right.
So this doctor file doesn't only have up the pipes and installed a pipe and has to have an operating
system with it right.
And so Python 3 has the buntu operating system so when we do this if we was this just a one line what
happens is Ducker pulls this image and it trons.
So this image over here.
So this image on the getup here has its own darker fall so if you notice each of these has a different
doctor.
Also if I click here for example on this Vulg. file you it would take me to.
So this link is OK.
So this link is not broken.
So you would notice here that it actually has another doc or files or if you notice here it's also pulling
from some other images.
And then it's doing a bunch of stuff so so that we have we don't have to write all these bunch of stuff
we just directly pull from it.
And and part of pulling from that Python repository is that it also have an operating system.
So we don't need to define the operating system and everything right can just go right away from bising
from Python.
And so once this line is done then we have a fully working operating system running a buntu.
And it's also running by Sunseri So that was you know super cool very short with just one line of code.
Now the second thing is we're now working inside this docker file over inside this machine.
You can think of the docker file as as giving instructions of how to build a machine from scratch.
Right.
So basically inside this machine right now and I'm building it step by step.
So I'll tell this machine that I want my work directory to be at slash user slash slash user slash source
slash app.
OK.
So what is this so it's basically saying that inside this machine inside this machine that's running
the buntu.
And by then I want my working directory to be user sourced at.
So why why are we treating this well this is just the convention we really work or put our user work
directory in slash or slashed or slash.
This isn't really anything special it's just they the common way people do it.
And so now we can think of it as we have a machine running a buntu with bytes and three.
And our working directories now in this in this here.
Now the second thing we want to do is to copy right.
We have a we want to install that dependencies right before we run our application we want to copy the
requirements that x.
So I'm going to copy and then requirements.
Let's see Rick wired mutants not text and I want to copy it.
So this requirements that decs is copying from here over here from over here and then I'm copying it
all the way to my machine which is running a buntu 16.00 for Python and this is it's working there actually.
So I want to copy it to the current work directory.
So I just added that and then I'm saying run some sync to the machine to the Abunda machine running
by then.
I'm telling it to run Pipp install and then no cache directory.
Make sure there's no cache and then are recursive and then requirements require all these compute this
one Rick.
Why your moments.
Yep there we go.
Requirement is that X so that we're going to tell the machine to run.
And also this machine is up to say it hasn't already passed by then.
So we do it Instow.
No cash there actually to install these requirements that DEXA we're going to install all of these Python
libraries over here.
The dependencies that we need.
And then after that we're going to copy dot dot.
So we are going to copy the current files.
So we're going to copy abduct pre-wire and requirements that text into the system.
Right.
So we're going to copy it into the current working directory and slash user slash or slash app.
So keep in mind that the first part here is what's on your machine right now right.
This is your actual code.
And then on the right hand side it's actually what's going into the machine.
So you're building the machine bit by bit.
So the first thing is you got the operating system working on bias and change the directory to here
to be that working correctly then you're copying a file from your machine to the new machine you're
building then you're running Peppe install on your on the new machine to install these requirements
on the new machine.
And then you're copying all your files your application and the UI onto the new machine.
And so the final thing that we have to do is just to write a command as a command distilling daquiri
to run a command.
And that's basically going to be Python and then Colma and then app duppy away.
So it's telling it to re bison run this command on the new machine python app that way.
So you can think of this docker file over here as we're building a machine with a web application but
we're building it step by step right just like how we did in the start.
The first thing is I taught you how to use the virtual box to download a buntu and Python.
So we had this from year.
And then the next thing we made a new directory right.
We made tutorial one on the desktop and and then we installed some requirements like flask and then.
So this is this one flask and flask restful.
And then we ran that we installed these.
So these two steps here download and install the new flask and flask restful on the system and then
we introduced to up into this virtual box here and then we once we were happy with it we were on Piscean
and up Pusey you can think of this as really a process of building the other system the new the new
computer if you may say from scratch.
Right so that's.
And that gives you a lot of flexibility with what you you want at your environment and what you don't
want in it.
So we say that for now and then for further requirements here we need two things we need a flask.
Right.
Sometimes it gives me problems for the f or f.
So this might throw some years.
And also we are going to with that flask restful or install flasks full rest folk.
So we just add them in two different lines and basically that tells pit install to install flask.
And last question right.
OK so far so good.
Now if we go back to the terminal and then we go so we go one step back and then we do sort of atom
here so we open atom here again.
Now what's happening here.
Now we have two folders we have database which we didn't put anything in and we have again a web a web
all right which has ADD UP WHY WE HAVE A or file the doc or file that explains how to run this whole
system web system or a web module if you may see onto the new machine and then you have amped PUA which
is on the outside right which the one we Capuzzo we don't actually need this one so we can delete it.
Right.
Move into the trash.
Now what we're going to do is we want to have some way to automatically start this web application right
away.
Right so we want some way to be able to run it right away.
So what we're going to do is we're going to be at the top level.
So for here we have D.B in web and then I'm going to make a new file which is called docker and it has
to be exactly this like this Dharker compose that YAML.
OK so Dr. Dash compose dot why and how and it's pronounced YAML.
So I click enter and again pseudo-ID you forgetting that.
And so if we go back to our atom here and see this Adam over here.
And so now we're going to be able to be writing here is a new or compose YAML file that basically contains
all these containers so you can think of it as we have so many images here right web database web to
maybe maybe have two web applications running at the same time and you will one file to control all
of these to control the communication between them to control what ports they're running on to control
everything about them.
And so the first thing is we're going to write a version and then three.
Right.
So we're using version 3.
There are many versions of blogger compose each have different syntax but the latest one is version
3 so we're going to be using version 3.
And then we're going to write services and then enter.
And then the first service is wed.
Right.
We're building the first one which is web.
And then we're going to tell Dr. Campos to build it from.
So I'm going to tell build from this current directory then Web.
So I'm basically telling this what I'm doing here is I'm saying when is a service and you can build
this service so you can build this web.
So let's go from the backwards.
You can build the web service from the they're actually at dot slash web.
So this is where the docker file is.
So at this location you must have a docker file so set so that this doctor compose would know how to
build this module right.
Because the doc or I remember the doc file is what tells the doctor or doc or compose how to build the
entire computer from scratch right.
And so this is basically selling it.
Hey I have a web not you and you can build it from this app from this.
They're actually over here.
So a not so great directory slash web.
OK.
And then I'm also going to tell it I have sports I want to open some boards.
And then the first port is 5000 whoops and that's 5000.
And then I want to match it to 5000.
OK.
So I want I mean if you remember we talked about ports before and it's basically matching five seconds
so I think this should be here.
Yes.
So five thousand to five.
OK.
Now once we're done with that then we're done.
Now let's say we add database which is another one.
So we add data.
So another service would be D.B and then I would say build you can build it from that slash D.B and
then D-B should also have a docker file inside of it that tells you how to build this database from
scratch right.
So you can think hey that this daquiri composed YAML file it might have it you might even have to write
and then this would have build and then you can build it from Web to write as though you can have multiple
services and all of them can communicate with each other very easily using Bocker composer.
That's why Dr. kapos is very simple because instead of just dealing with one docker or container image
at a time you can just communicate with all of them using block or compose so that's super useful.
So for now we don't have anything for a database or web.
Those are we going to delete it and leave it as it does.
Now we're going to save that and that's about it.
If we want to run this system so you just save this and then we're going to go back a year and we're
going to have the first we're going to first ride pseudo darker compose build.
So we want to build the entire system first.
So we have an air
OK so I think the problem here is this this space over here.
So you need to have a space between the command and because when you're you notice when you have it
here you stuck to version and so version wasn't considered right.
So you just have to put a space here and hopefully once you do that then that should hopefully work
great.
There shouldn't be any problems and then you go out and you do soon to build.
And so I was going to tell you that it's building weap right.
So is for us going to pull from by then.
Right.
And it's basically pulling from where.
Well it's pulling from voc rehab like we discussed and so I was going to download it and do it.
So that's step one out of six so I'll come back once this is done.
So you'll notice here that the first step is done and we have downloaded basically by in theory and
the operating system and then they start step two which is to make the work directory as last users
last slash Flash app and then the steps three is to copy the requirements that Daggs.
Step four is as we said to run install.
And so now it's going to be installing flask and flask restful.
OK.
And so now it's downloading.
And if you notice here that we downloaded everything we've copied and now we're running BIOS and amped
up the way.
OK so now that we've done this and we've built the system successfully then now if you want to run this
system then we would go to and write pseudo doctor compose compose and then the last time we rode to
dock or compose build.
But this time round your eyes Sudhakar combos up and so click this and then we write the password to
here.
OK.
And so now you will see what it's doing is it tells you we're creating the network to Turo one default
was that was the default driver.
And it's attaching the instance to it.
And it's saying environment is production and this is where we're going to talk about this later.
But it's basically saying that your server is now running it went to seven point zero point zero point
one.
I found it and so whoops.
So we've accidentally clicked Control-C to close this off.
Close the the server.
But if I rerun it again.
So let's try to rerun it again.
And OK so it's running now and you would notice here that it's running in the site.
So if we go here and we click on the year and then we go control the so we can tell you that the connection
was reset.
So yes.
So OK so I found the error.
So in this year if you remember when were running that application that we need now in this case we
need to specify that the local that the host to run this application should be the local host.
Right.
So we should run this on the local because if you see here in the previous ones we were running on one
to seven point zero point zero point one.
But this is the local host of the machine itself right.
So what we need to do is to to change those so that it's actually an ad.
If you notice here it says it's running on zero point zero point zero point zero.
So the only thing we're going to do differently is to go back and to run the host add host equals zero
point zero point zero point zero.
Now if we open up post man and we go and we try to do some sort operations are you going to do local
host OK 5000 slash ad and then let's change that.
For example to try to maybe zoomin.
Are you seeing this.
OK so so let's try to make X as for right.
And why is 5.
And then we want it whoops we want to save that.
And so we can send this this information and then we should get their response back.
So if we go here and we see the bodies let's see how we can make it even smaller now.
So the result is status code is 200.
And the message is nine so four plus five is nine.
So if you do that instead as divide right or it was it division I think.
So we closed that and we said and then we get a 200 0.8 so for divided by five is your appointed.
So you get the idea.
So basically what we've done here is we've reduced the system to one dog or file which is controlling
all of the containers.
And then this container here contains only one web application and IPY and this adds up to why is running
inside a container that is specified by this Dharker file over here.
So this Dharker file is.
You can think of it as a separate computer or a separate server and it running in a buntu machine with
Python and it has all the requirements flask and flask restful and it's running at the Y at all times.
And so it's trying the web server.
And this is a requirement that text.
And so now we have a system where what if we want to do it.
So let's say for example I want I come here and I want to do is change yours or let's say I want to
do this is message one right or do something so I can say that.
And then once on I want to test my code I just Control-C eat.
So I stalk my daughter compose and then I rerun Sudhakar compose up race only you don't need to do to
do a rebuild unless you change something in the file address and you add a new file or you change one
of the darker files then you need to run build again.
But if you only if you don't need to.
You can just do Sudhakar combos up and so it runs your server right away.
So this is very very very quickly in that we can you know work do our code here do our changes and then
just run the server and voila all the systems are running all the databases everything is running and
we can test the code right away.
So this is super helpful.
For now it just seems like you know I might hear someone saying Oh we can just use you know Python flask
or or or just from the terminal on say Dyson laptop you why does this.
Answer that.
But later on we're going to add a mongo TB database and we're going to add more stuff.
So you're going to want to have some way to control all these systems.
And the best way to do this is Dr. Campos so you can with only one one command you can raise all the
system up.
So hopefully that makes sense.
We haven't done any Lots of changes.
In fact we only wrote this or file.
Dr. gumbos and we only installed darker and darker compose on the system so nothing too major right.
We've only added like these are the two major files that we've added and we've done some re ordering
in the structure of the code.
Right so it's now D-B weapons stuff like that.
So yeah.
Thanks for watching and I'll see you in the next video.