Docker Compose #0002

· 46 min read

I used this git repo in this session.

GitHub - beacloudgenius/dockerfiles: multi container architecture
multi container architecture. Contribute to beacloudgenius/dockerfiles development by creating an account on GitHub.

AI Generated Transcript

So hey guys, we are running this live teams meeting and it's also being streamed right now.
Let's go test whether the stream is successfully working. I think it is and so let's go test it out
on LinkedIn. Is my stream live? I think I got a notification on yeah it is live.
So that's the live stream. And let's see on Twitter. We should be live on Twitter as well.
Here we go. So notifications on my profile. We should be seeing a live stream of us talking.
Like that's where we should show up. So there it is. And so this is the live stream happening
on Twitter as well. And so I'm not interested in seeing the live stream, but it's very
interesting our meeting. So that's what we're doing. So let's recap. What are we discussing?
Docker. I have this Macintosh in my hand. And I want to connect it to a Linux machine.
That address of that machine is 192.168.1.10. It is an iMac.
And it is in the same room that I have, so I can locally SSH into it.
And this machine has Docker installed and EOCKER. That's where I will be experimenting.
So for this experimentation today, we will discuss Docker and Docker Compose.
And I have a Git repository already prepared. I will give you a link to that so you can actually
use it. And I will also clone that Git repository locally onto this machine.
And using it will be a good demonstration of what Docker Compose is and how you can put
things together to construct a variety of applications and run them in Docker containers
plurality, like more than one. So multiple containers coming together to form what is
needed as an architecture for your given application. That's the design point.
So we are looking about talking about a Git repository. I have that repository with me.
I will open up a browser and show you that repository and also tweet it out so you can
access it. So here I go open my browser and go to GitHub. And
here in GitHub, I will have to go look for it. So the repository is in my company account
where the thing is called Docker files. I think that's the
repository. No? Yes. Yeah, that's the name. So I'm going to go there, Docker files.
And this is a public open repository so anybody on the planet can access it. So there it is.
That's the repository. I'm going to grab that code link, copy it, and then use that link to clone the
whole thing locally into this iMac, the machine that is running Ubuntu. By the way, this iMac
is not a Mac. It's just the machine is Mac. It used to be Mac like a few years ago.
Now it is running Ubuntu. So that is where I want to bring this Git repository and put it right there
on this box. So let's go there. Terminal. And right now this is the Macintosh.
You can see it. Now I'm going to SSH into the machine, the iMac. I SSH. Now you see that this
is an Ubuntu machine. And there I already have this thing Docker files cloned. So I don't want
to use it. What I want to do is remove that folder called Docker files, which I cloned yesterday.
So I'm going to remove it. And so apparently permission denied because I was like running
something running there. So I'm going to go clean it out completely. So sudo rm-rf Docker files. And
it should die. It died. Now nothing is there on that folder because the folder itself is cleaned
out. So what I want to do next is make it bigger and then git clone. So it comes down. The folder
containing the entire repo is now available to me in this location, Docker files. And that's the
folder. Here you can see inspect the contents of the folder. So there are exercises here that I
will be doing live that will explain what is Docker Compose and how we can put things together to run
a multiple container application structure. And we can use buzzwords about end tier architecture
and all the buzzword bingo. I don't do buzzwords. Absolutely no buzzwords in my talk. I talk simple,
plain, but get things to work. That's the idea. So this is the folder we are looking at.
And I want to go to that folder so that you can see it in a visual fashion for which I will be using
a visual editor. So here it is, VS code. Actually, this is not VS code. So what Microsoft does
is they snoop and look at what your activities are and they monitor you.
So that is a bad behavior, so I don't like that. So what I do is, actually what many people do
is they have forked this thing called VS code and they have created a thing called VS code M.
So I'll tell you about VS code M. Here it is VS code M. This is actually the open source clean
version of VS code. Open source libre, like open source as in no monitoring, no Microsoft nonsense,
clean, genuine, open software, which has no relationship with Microsoft. That's what VS code
M is. It's basically VS code. VS code is open source by Microsoft, but many people have
contributed. Many people have modified VS code to create this thing called VS code M, and it is
a very good product. Why? Because Microsoft would not know what we are doing. If you open VS code,
they will know certain things. I don't want anybody to know what I'm doing, unless I'm
disclosing it. So privacy is important to everybody, including you and me. So we are using VS code M.
So not VS code, code M. Slightly different, very, very similar. Everything works just like that,
but Microsoft does not come in the way. Nobody comes in your way. That's the underlying concept
of freedom. So when I talk about free, I actually think of it as a free environment.
Free means freedom, not zero dollars. That's not what I mean. Free means freedom, and that's what
this thing gives me, open source. So VS code M is what I am running, and there I am going to connect
to that machine, which I told you about like that, and then hook it up. So this is a VS code M
connection, remote connection to that computer that I told you about, and there it is. So you can now
look for that folder that I cloned, and it is, what was it, Docker files, something there.
So that's the folder. If you can see it bigger, a little bit better. I think that's better. So here's
the folder called Docker files, and in there you can also, by the way, locally clone. If you have
a computer with you, you can clone it, and you can see it. And what I will do now is in that folder,
by the way, this is the same machine that I was talking about. You name iMac. The same iMac is
what contains that folder called Docker files. Same thing. That contains the same exact thing.
We are now remotely connected through VS code M into the machine, and we have the files here.
So the reason I do it this way is so I can actually look at the step-by-step instructions
and show it to you, and then follow along so you can understand what's going on.
And this is basically a hands-on exercise. Everything I try to do is hands-on, and it's
written down in some Git repo, and we'll actually execute instructions. That's the idea. So having
said that, let's do it. So step-by-step. Here is this part one, like the first step. The first step,
in that first step, what we have, let's get rid of these browsers. So browser window closed.
Don't want this. I think you need to tweet this out. I'm going to tweet this link.
Tweet that with the reply, I am using this repo today. And tweet. So people will know.
And so people who are looking, they might see it.
Okay. And next, what I want to do is run these steps that we have. So in our step-by-step folder,
we have this file called one. That one, file number one, that file. It has written instructions
that only I can interpret and understand because it's not very nicely written. But I know what I
wrote, so I can explain it to you. The first thing, A and B are equivalent. What I mean by that
is this step A, that I highlighted in blue color, is very, very similar, actually identical,
equivalent to the step B here. It's basically the same thing. What do I mean to tell you
is that this is execution of docker-compose on the command line. Whereas the B section,
Nilesh, here B, these two commands, one at a time. So one and two. So two separate commands
versus this command. Nilesh, can you hear me for a second?
Yes. Yes, Sanjay. Hi. How are you? Yeah. Yeah. Good. Good. Hey, Nilesh, can you,
I think, first of all, I'm getting your screen cut off in the left-hand side and the right-hand
side, all the participants are getting displayed. So half of the thing is basically that participant
the screen is taking. So I know that's a problem with teams. So I don't know how to fix that
participation videos. You have shut off your videos, which is nice. No, no, no, no. But you
still see the circles, right? You still see circles. No, you just, I think, show participant
or if you remove show participant on your side, then those will go away. Only your screen will be.
I understand. I just don't know where the button is. Can you tell me?
Oh, no, I'm a participant. So I get that. I think it's better now. I think whatever I did,
but half of the screen is taken by those participants and half of the screen is
only displayed. So I made you a presenter and can you modify it to suit what you need?
Okay. Oh, you made me a presenter. Yeah, I made you a presenter. So see if you can modify. I just
don't know how to hide other people's circles, right? That's what I see coming in the way on
the right side. Is that what you tell me? Yeah, but that's okay. I think my screen is 32 inch,
so still I can see what you're doing on the left hand side now. I think I noticed that this issue
that I don't know how to fix is with teams and the teams, what it does is like gives me circles on
the one portion of the screen. Like, you know, about 20% of screen is wasted, which is not a
great idea, but I will look at and ask somebody in Microsoft as to how to fix it, but I just don't
know right now. Yeah, go on. Basically, I have a big screen, so half of the screen is going with
that. That's of no use, but that's okay. Go ahead. Sorry, I break your. No worries. So let's see if
I can remove you from presentation and then see if I can keep sharing and making myself full screen.
Let's see if I can highlight myself as a full screen person like person with view. So view,
I want to get full screen. No, that's not what I want. So view, I want to get.
Gallery at top maybe maybe that fixed. No, did it improve improve something?
I don't see what you see. That's the challenge. So tell me if it is improvement.
Tell me if it is not good. Tell me that too.
I think nothing is happening on on your side, but things are happening on my side. I don't know how
to fix that issue that you brought. I will take it away. Nilesh, what I did. Sorry, this is just
small thing. I did a large gallery preview and everything got fixed. Now everything is in middle
what you're showing and participant went down somewhere. I see. So the way to resolve for
everybody else will be what again Sanjay? Yeah, so you that press on that three dots that is
horizontal three dots and there is a large gallery preview. Just large gallery preview. So select that
a large gallery preview. OK, got it. So everybody please select large gallery preview in your view
after you click the dot dot dot in the teams meeting. That should resolve most of the problems.
Yes, it's done now. OK, nice. So now I will continue. What I was talking about is that
these ways of running certain things, right? So let's go see what I did here in terms of
this is the a scenario. Right and then the B scenario. So this is a this is B. So let's go
see what then what I am actually meaning by these two ways of executing the same idea. So let's go.
It is this ink. And then. Execute one of these things at a time. So we have this command called
Docker compose and then uses a file here called dash F and then I'm looking at line number five
in the screen here. Line number five, this line and Docker compose uses this file reference here
called one. Docker compose J Wilder yaml. That's the file name that file is somewhere here. I think.
One of I think that's the file I'll cross check and then you bring that stack up. So Docker compose
will bring whatever is defined in this file will bring it up and run it in demon mode.
That's the idea behind this command. So we will check whether this file that we are referencing
is actually this file here and will examine that file itself and read it and then execute that
command to see what actually happens. So let's cross check whether it is the same file. Yes,
it is. So so this file is what we are executing in this section and we're bringing the stack up,
putting in a demon mode and Docker compose will actually inspect this file to do what it's supposed
to be doing. So let's go read that file ourselves and then let's see and understand what that file
actually contains. So here we go. Go open that file that I have and inspect. So let's go see what
is inside here. Inside we have this file and there are two services defined. One of them
is this portion. By the way, if you're reading this file for the first time in your life,
I should warn you that this file is a YAML file and it is very very finicky in terms of indentation.
Indentation. It is like Python indentation. If you have the indentation wrong,
like how many spaces, how many tabs before every line, then the whole thing breaks and nothing
works and nothing works. So be super careful with your typing and especially indentation,
which is whatever you have before this I or before the W. So here this side,
how many spaces you have, you have to literally count every space or every tab that you have put
and it has to be properly indented for YAML to actually work. If you now look at this YAML again,
you will see that this indentation or indented block is one service and this is another service.
There are two services defined and we will, when we execute this docker compose, it will bring up
two docker containers. One running this, another running this. Let's go see what those things are
and let's begin with actually running them and see if we can actually understand them in the
context of a runtime. So actually execute these things. Let's go run it. So what do I want to run?
Step number one, line number five and there I will execute the step-by-step instructions
just like that. Copy it and it says docker compose not found. So this is a change that recently has
happened in docker where early on docker compose used to be a separate piece of software. Now docker
compose comes with this thing called docker. What do I mean by that? What I mean to tell you
is earlier the command was like line number four. Now the command is like this
because docker compose is now a part of docker. So you don't need this extra piece of software
called docker compose. It used to be a separate software early on. Like this was the software.
You needed it separately installed but nowadays docker comes with compose and it is structured
like this. So what I have in my git repository is the older way of running docker compose whereas
I need to modify and remove the dash symbol. That's all I need to do to make it work. So let's do that.
So that's the new docker compose by the way which I have to modify this file. So I'll modify this
file everywhere. Docker compose everywhere you see. Docker dash compose. Make it docker compose.
It's two words. So I will now copy that line. I am line number five again.
Oops and paste it and that should bring up two new containers and it's pulling them right now.
You can see it's being pulled and those two containers are starting and something happened
and something failed and I'll tell you what failed and how do you bypass that and all that.
I'll discuss that. So let's go see what failed. So here's the failure and this failure is expected.
So nothing you know abnormal about it. It says bind for port number eight zero failed because
it's already allocated. I am using a bunch of things in this machine already are using that port.
So it cannot be allocated to another application. This current application that I'm dealing with
right now that I just started or attempted to start wants to get the port number eight zero
but is occupied by certain other things. So what do I do? But I sidestep. How do I sidestep? By using
some other unallocated port like I'm going to modify line number seven just like that.
Yeah I just inserted some other port number so that this particular container will run on that
port number eight seven six zero randomly chosen number and I think it is not allocated. Eight seven
six zero is not taken I think but let's see what is taken in my machine here. Docker if I look at
docker ps-a you will see a ton of processes like here all these guys. Lots of things are running on
that machine called the one I'm connected to the iMac and bunch of services are running and at
least one of them is taken over this thing called called port number eight zero and I don't want to
you know basically like this this new app that I'm trying to invoke here cannot cannot get that port.
So I modified my port request like like I did like I showed you I'll show you again
like number seven I modified the port that I wanted it was initially eight zero but I made it
two eight six eight seven six zero that's the change I made and then I can instantiate this
stack one more time and you will see that it is running and it started. So let us see what is
running and you will see that you know top level object must be mapping.
I think these two are running so let's go let's go test them. How do you test? We have to go read
that docker compose file one more time and what are we looking at is that we have to go let me
explain this thing to you a little bit. So what this container does is it it maps itself on port
number eight seven six zero on the iMac and then that is mapped to the port number 80 on this
container called nginx proxy and this proxy in turn will look at the other container running here
called whoami. Whoami is a different container running this image whereas this nginx proxy was
a container running the json builder nginx proxy image so it's a separate container this container
is looking at this container and actually showing you whatever this thing is so there is some result
some output from this container I want to see that and so this proxy is actually looking at the
result and showing it to you on that port that's what the structure of this docker compose is it's
a very simple example let's go inspect whether we can actually see what we are talking about right so
I will now attempt to open port number eight seven six zero on the iMac let's see what happens when
I open browser and open the iMac and then port number eight seven six zero and let's see what
pops up this service temporarily unavailable this guy eight seven six zero is not responding
properly but it is showing you nginx that means this thing is actually running the right set of
uh uh service that we expected to run this is running nginx and nginx proxy so this thing is
actually correctly showing you that it is running nginx now the other part of issue that we have
is I want to be able to see the whoami application like this this application I want to be able to see
and that proxy should connect and show me what this guy is showing you and that is what is not
visible to us so let me explain and elaborate what is going on and how do we see what this whoami
is showing you and so that we have to go back to this file and read the instructions of that file
to understand what are we actually dealing with so let's go back to here and how do you test it
when I try to open that browser it did not show you any result that you expected to see but showed
you that there is something unavailable although it shows you it is being given to you by nginx
which is the nginx proxy running by the way it doesn't show you our whoami output
whoami output is not visible to us on the browser window but let's go follow the test instructions
so you will see why it is not visible and how you can make it work so that this very simple
subtleties are involved here to understand that's why you had to go back to the write up and and see
how to test it so that this test step in line number nine by the way you have this repository
with you on an open public github repo and now you have a link on the tweet so you can see it
now let's go back to the terminal command line and follow the test instruction line number nine
and see what actually shows up I did not copy properly so let me copy it properly here I go
and then I will expand the screen and test it like that now I'll describe this test instruction
to you first let us execute and see what I what it does it says move permanently and if you if you
go to move permanently that is let's go let's go curl this thing with a dash i option so
to see the headers and it is going to HTTPS by the way so it has redirected to I think I think
there is a change in nginx proxy created by json builder which is what is forcing you to use HTTPS
and its new location happens to be this so it is not going to show you on localhost because
nginx is forcing you to go to that domain that is specified in the in the docker compose file so
let's go read the docker compose file one more time and here it is you will see here that I am
let me describe the docker compose one more time before we actually go further investigate and test
and get it to work so here this this file here let's go investigate that piece so here in that
file I have defined that this who am i container will be using a host name foo.bar.com and that is
what is being picked up by nginx proxy as the name this container should be using so if you go
directly visit the ip address where this container is running it will show you unavailable that's what
you saw in the firefox browser when we try to visit this through curl command it is telling you
that nginx proxy has modified and this thing is going to be forcefully require you to use HTTPS
and not just HTTP if you now go back to our curl command it is forcing us to sorry it is we are
using we are using HTTP command not HTTPS you see a direct reference to localhost no reference to
foo.bar.com so what I need to be able to do in order for us to see this is for the DNS to work
now for some of you DNS may be a new thing but I'll illustrate a quick simple way to work around
for DNS to work properly on the machine that I don't have a control over this bar.com domain
I don't own it but I can bypass that by using a file called etc hosts so let's go modify that
etc hosts file and insert this new domain entry on the etc hosts so if this is complicated ask me
to stop and explain I will explain if you have done this kind of thing before
you know tell me to continue along so what I'm doing is modifying my host file
and in that file I will add on a new entry called foo.bar.com and this goes to localhost
sorry the way you write it is
like that that's how you describe that my domain foo.bar.com belongs locally to this machine
and then if you curl the same way except this time it will be HTTPS we'll get a certificate
failure error because we don't have a proper certificate that is expected
see certificate problem so what I will now do is allow each of these to work
in a fully configured proper certificate example which is also probably in this same exercise set
or maybe we'll do a certificate related thing in another session you will not run into certificate
problems like you are running into right now because we don't have a properly signed
certificate we are issuing a self-signed certificate you have to bypass it so how do
you bypass a self-signed certificate you have to bypass it so how do you bypass a self-signed
certificate you have to bypass it so how do you bypass a self-signed certificate you have to
provide some insecure flag I think let me just quickly check how do you pass a insecure flag
curl insecure how do you specify that how do you ignore the way the command is I think that
that's insecure that's it so that's the command we transmit in our section and this should give you a
interesting
still not showing you the right I'm still seeing a permanent redirect issue which is
something that I I don't know how to explain this right now and we also check our time
as to see how much time we have elapsed we already have about 30 minutes passed so let me show you a
slightly more interesting example instead of this curling and command line thing a slightly more
visual example which is also in the same set this can be daunting for people who are not used to
command line and curl and secure certificates and all that so let me let me jump to a simpler example
which may be easier for us to comprehend what we are dealing with in a slightly easier fashion so
what I'm going to do is skip the step-by-step I'll come back to this in another session I want to
jump to a simpler example of a docker composed and this example is an empty file all these things
that you see here are basically comments so you can ignore the comments by leaving them alone
and what I want to do is grab this example copy it from here from this file and put that in the
docker-compose.yml file like that that's it so what did I do I copied from this example called
three tier which is there are three tiers here one two and three three tiers of architecture
and put all this file from from this file I copied all the content put that in this main file called
docker-compose and I will a little bit edit this file because there are some changes that we need
to make like we did before so before I jump into the actual action I want to make sure that I
in this in the step number one here we have the docker-compose I want to bring that down
one dash docker-compose.jwilder.yml and I want to bring it down so those two containers I was
running I removed all them all of them and then I will come out of this step-by-step folder and now
I have here what I did do is I copied the content from the docker-compose.yml file and then I
step folder and now I have here what I did do is I copied the content from this three tier example
file and I put that into this file this was empty to begin with by the way this file was empty as
you saw here it was like this before and I took content from the three tier file and put that in
here and what I want to do here now is the same port collision problem I want to bypass it I'll
say eight seven six zero some port modification I did line number 26 so that allows us to bypass
the port collision and I want to see if we can bring this entire stack of three containers up
and running for us to get some gratification of something worked finally that's what I want to
get to like something that you can actually play with so I will attempt to execute this
get it to run and then we'll describe it as to what that means and how do we actually use
this thing in real life so that's what I will be doing now I will close this file from here
and get to the terminal and then say docker compose up and see what happens and I think
something happened so let's go see what happened and whether it works so I will open my browser
and there I will go to that same machine and go to the port number eight seven six zero
and see what shows up and there we go we have something working finally so this is a ready-made
example so I'll need to dissect it what what this thing is by the way it is a wordpress application
which contains three different containers for it to work properly what are those containers
let's go see them here in our three tier example which we took from here and copied that into this
file the docker compose yaml file which is how the instructions are laid out that's how I wrote it
so what do we have here we have this instruction set copy the yaml snippet from the example files
and paste them into this file and then bring up the stack by typing docker without the dash
so just these are older instructions so remove the dash the newer docker compose does not want
the dash so you just don't have it and say docker compose upd and that will bring up this stack with
three services let's go see what those three services are the first service is this
very simple and I'll describe that the second service is this
by the way this is a trivial example don't put this in production don't run your website
containing wordpress using this instruction set it's not a good idea but it's good for
understanding conceptual understanding of what this thing is so that's the reason I built it
this way this is not a production-ready design so don't run it in in large numbers it's not
designed so don't run it in in live production and for your customers in your wherever you are and
just come back to be saying hey something went wrong please don't do that so this is not for
production not good for production just a caution this is good for understanding that's the reason
why I structured it this way so not for production repeating that don't blame me having said this is
the second service running a database and the last one this is a service running wordpress
so what are these three things again this is the application this is the database and this is the
place to store data for the database so the connection is like this this guy the application
container will use the database container which is a mysql database i think no maria db so it's
the same basically the same thing so maria db is like mysql but better why better
because oracle doesn't come in the way so these big companies like oracle and all the big companies
like them misbehave basically they misbehave they want to you know put unnecessary license
conditions they want to extract money from you so the oracle got mysql and they put some god
knows what license on mysql and so people did not like that so what did they do just like vscodium
and vscode people took mysql modified the code it's open source and made maria db and removed
all the oracle things so all the bad things that you know bad as in legality and you know bunch of
other big company nonsense you remove all that and make good database called maria that's basically
compatible with mysql you know exactly even it even it uses the same syntax you can see it
but it is a different application called maria and it is i think better than mysql so that's what
i'm using here and it is a container and it requires a place to store the database data
and so what it does is get this storage location from here
and so this guy uses this container and this database software uses this place to store data
so let's go begin from the top down now so at the very top we have a service called data
which is building something called data and what that means is building a folder called data and
where is that folder right there
so we have to go inspect that data folder to understand what happens when you build this
container and run it when you say docker compose up what happens that's what i want to show you
so we have to go inspect this folder here which means i will erase my ink
and then use my mouse to go to the data folder and there you will see something called a docker
file right right there that's how it is it's a very simple docker file and what it does
it instantiates a new image called busy box so very very small tiny 1.2 megabyte image
very small linux image like really tiny and this busy box image is available on
where is that now firefox browser and let's go to docker hub busy box you will find that it is a
tiny tiny image called busy box it's it's a barely working linux just the minimum parts and this is
what we are using and the size here is like very small you can see 2.2 megabytes and that's it
and this is what we are using and the size here is like very small you can see 2.12 mb
1.85 mb so tiny tiny sizes really small size os so that's a good thing small is beautiful by the
way don't mistake small for for useless similarly you know people ask me this question about
lightweight docker is a lightweight container software don't confuse lightweight with heavy duty
lightweight doesn't mean light duty it can do heavy duty stuff it does they do heavy duty stuff
you know so don't confuse lightweight with you know it cannot do big things it can do anything
you want as long as you're following the instructions it will do it so what i'm
what i'm telling you is lightweight is a good thing heavy duty is a good thing don't confuse
lightweight and think it is light duty so this is a lightweight container image very good i love it
i love it busy box another one of my favorite is alpine alpine linux it's good for containers
and container design and applications using containers the alpine thing is like tiny tiny
how much 3.25 megabytes beautiful most of my actual running applications that you see
that i that i run are actually using alpine so very efficient small powerful lightweight
heavy duty you know container image you can create and you can basically so understand these things
like small is beautiful and that's what you need to keep track in mind just to give you a contrasting
example here it is where is that windows windows let's see windows what pops up so when i think
they i think they took away they took away microsoft took away windows from here
they are their own container registry where they store images but just to compare and contrast the
smallest size of a microsoft windows server image for a container is used to be i don't know currently
if i'm wrong five gigabytes yes five gigabytes imagine the waste of time and effort and storage
and bandwidth you will have when you want to pull down a docker image containing what
five gigabytes are you kidding me yes there are people from microsoft who will listen to my talk
that's too bad i'm going to expose that that's a fact compare with alpine you cannot compete
that's what open source is so just be remember that don't forget it small is good
small is good so let's go back here so this busy box is another small image that i will be using
i am using and i am exposing exposing this folder as a place for us to store data that that's it
that's the entire design of this particular data storage location so what the container does it
starts the container and exits and provides a volume a volume reference for other containers
to store data in this location so the database container that i have that i will talk about next
basically uses this volume to store the data in that location bar lib mysql that's the location
that mysql expects to store the data for the database also maria db same thing same exact
location that's the location so i will use the database container for maria db and let it read
and write from that location so that's the distinction of what i'm trying to differentiate
is the database from the place to store the data for the database so there are two different things
what this thing gives you is a place to store the data for the database and what this thing sorry
hold on where is that yeah what what this container does is actually runs the process maria db process
basically mysql like process where it will mount this folder inside the container
into that location in the macintosh somewhere here somewhere here i'll identify where that is
and store the configuration you did for this this for the mysql database to run properly
and mounts the data storage from this service so that's the database here database server
database server and this is the place to store database data that's a place storage
that's it there's nothing else in this particular piece of puzzle just a place to store data
this is the service that you're running that runs maria db and runs like a database server
so that's the second piece of the puzzle third piece of the puzzle is the actual meet the real
thing which is the application you want to run so this is uh i will describe this also let me just
pull up and refresh a couple of things here and so here we go there so now we now you see things
here there we go now so now what i'm talking about is this section here
which is by the way already in this location in the gtrepo that i i shared you a link with
and it is mounted inside the maria db container in that location what does it do it passes a custom
configuration to the maria db image so that when this container runs it takes my customized
configuration into the container and configures this database container correctly the way i want
and this allows me to have this other container third container to actually communicate successfully
with the database with proper permissions if you don't have permissions this guy will run this guy
will run but it will not be able to talk and that's what this custom configuration does
so let's go see and inspect that custom configuration here it is and all it does is basically allows
the bind address of 0000 so this is like specific to database implementations of maria db
like pi sql in a containerized setup by default maria db will listen on this port
and this ip address only internally to that container and that means the other containers
cannot connect to it so you want to modify the bind address
not this but this
and that is the only way that that's one of the ways there are some other ways also that this is
the one of the way the easiest way is to get some other container to connect to the database
container so that permission i needed to expand and which i did that using this custom configuration
like that and this configuration file gets mounted and it will be able to connect to the
configuration file gets mounted at the time of execution into the database container like this
line number 16 excuse me i need to mute
yeah so that's the configuration passing over to database container and oops i need to erase the
link i erase that and now we will talk about this the third container which is the volumes that we
will pass this location where we will store everything inside the wordpress the user generated
content of wordpress is stored in this location in the wordpress container this is your wordpress
image it is running on that custom port that i chose it is linking up to the database here
like that db goes to this db and links up to that thing called mysql it like mysql it's actually
maria db and mounts this folder here which is also here onto the container inside
and that is why you are able to actually make use of this wordpress image which in turn connects
to the mysql database maria db which in turn stores the data in this location so that's the
design now let us see whether we can actually put this application to use so i will go back to the
browser and see if you can connect to it so here's the browser and there i am looking at wordpress
interface so i i feel happy about that then i go continue and it says give me the database name
username password host and all that so i say let's go the database name i'll be using is whatever
the defaults are so i'll just use the default name wordpress and then by the way wordpress
is open source just so you know and so you can modify it if you like so here's the wordpress
database name i chose to be wordpress username i chose deliberately to be whatever the thing
gives to me by default what did i do that just to make it easy on me and you can actually choose
a custom username i deliberately chose username username username in line number 19 in the docker
compose file you can see it line 19 right there i deliberately chose the password called password
in line number 20 right there the database name i chose wordpress as wordpress in line number 21
why so that i don't have to type these things because that's what the software automatically
gives you so i'm lazy i think some of you know that so i don't have to like type in this thing
so i just chose it to be exactly what i wanted it to be so i don't have to do other stuff like
modifying this entry modifying that entry modifying i don't have to this is a bad idea
by the way if you're doing it in production so you don't want to use a username called username
and a password called password don't do that but i'm doing it because it takes my life easy
now this database host is not the same machine or the same container running the wordpress
this is not so you have to modify that this needs to be changed because the database actually running
the host is this one not the local host so we'll make change right here and this you can keep it
the way it is it's not that critical although you can modify if you want to have a different table
prefix in the mysql database you can change the prefix if you like excuse me so what do you think
i should put right there i should put this name db so that name goes in here so that my host name is
in here so that my host name is db so i will make that change like the db that's it and then i say
submit so it says all right sparky you made it through this part of the installation and so
wordpress now can communicate with the database and you are ready to run the installation so
we'll go click the button and we have wordpress running so now we'll set the title for this thing
called you know what i'm going to be doing we'll set the title the cloud seminar the username
is nilesh the password it suggests you very strong password which is a great idea
but you know what i'm not going to memorize all that nonsense so i'm going to erase that
and i'll say password is one two three don't do that in production it's a bad idea so i confirm
the weak user weak password one two three is my password my username is nilesh and my email address
is my company address which is this cloud genius and then i'm going to discourage search engines
from indexing this site for now because i don't want google to look at what i'm doing right now
i'm not ready to show because i am not properly dressed up i mean my site is not dressed up
properly for public visibility so i'm discouraging search engines to index this site because i'm
telling them i'm not ready and when i install wordpress and now we have wordpress up and
running i need to log in and i need to type in my username and my password and then i
password and then i login and that's how it works right as simple as that there are some updates
available and some plugins and all that nonsense but you can dismiss this and look at the plugins
and see there's a newer version update now fine updated done what else we have nothing clean out
there are some more updates so the updates keep coming we can update later on but the idea is we
are able to create a new post like that so hello world you can modify it and maybe just view the
post right now this is how the blog looks like the wordpress blog looks like that hello world
so what i can do now here is go back to that site again which is this site and there i will modify
go to the dashboard and look at our posts that we have the hello world post and i edit that
and call it come on go away i call it hello cloud genius and update the post and then
view the post there it is so it updates so what are you what are you looking at is a functional
two-tier architecture with some backend storage that that's the design so let's go look at the
look at the design one more time so i'm going to go back to our notepad and describe the diagram
of what did we create and by the way you can also do the whole thing just like i did you can do it
on your machine provided you have docker properly installed with the latest docker docker compose
comes with docker these days so what did we do we have a machine i call it the imac it's actually
ubuntu it has docker running docker the app the software running docker compose also available
so we created three containers one container called wordpress this was exposing itself on
port number 8760 but it was mapping itself inside like that
so me as a user can visit the imac on that port and see what wordpress is showing me
this wordpress container in turn connects to a database container running maria db
and that container runs on port number what three three six nine if i'm not mistaken i don't
remember right let me just quickly check maria port my sequel port my
sequel port number
what's the port number three three zero six three three zero six okay so we should not three three
six nine but three three zero six at the port that this guy runs mysql and wordpress connects to
that port on the maria db mysql container and this container stores the data in the mysql container
and this container stores the data in a location called where what is the name i forget what's
the name again uh where lib in the docker file where lib mysql so where lib mysql that is where
the maria db mysql container expects to write files in the database so it is exposed to that
location through a separate container i created called data and this is simply for illustration
and separation between the database and the actual storage so this is the database service
and the storage location just to separate that out is the reason i created the third container
to illustrate the point that you can kill this container bring it up again as long as you have
the storage separate away from it there is no problem your data remains intact so just remember
your data remains intact so just remember that similarly this guy stores the data outside in a
folder called what is it called let's go see it is storing the data in a folder called where is the
file compose file it stores in that location somewhere here in line number 30 right there
it stores in this folder called docker files and wp content that's where the actual storage is
you can see that you know the storage goes right here wp content that's where the storage is
there so what does it mean that means that you know this this whatever you store in the
application called wordpress it will actually be stored on the imax in a folder called tilde slash
docker files slash wp content
that's where the files that you put in the wordpress application will belong the data will
belong in this storage for the database so just remember that there are two storage locations
for these two containers and we are keeping them separate the reason i i designed it this way is
to illustrate and drive home this simple point which i will now demonstrate next is you can kill
the container and it doesn't matter as long as you're preserving the data outside you don't
remember to preserve the data away from the container so the key takeaway here is keep your
data away from the container that's what i'm doing see wordpress data is outside the container
database data configuration outside the container data itself also outside the container so three
things separately stored not in the container but outside what does this give us what does this give
what does this give actually is the ability to die and resurrect you can come back online no
problem let's go see if it actually is true so we have these three containers right
the data container which stores the data so i will leave it alone we have a database container and a
wordpress container i will kill this guy and kill this guy and then bring it up again and you should
see everything like like it was let go begin and actually test and verify that nilesh is not
bullshitting let go see it so i want to kill this container called docker files wp1
died okay and so that that means our browser should show you nothing so here we go refresh
nothing right so what do we do now we bring it up docker compose up
up and then we go to the browser and refresh
and it says continue our application came back let's go and so we have to go back to db submit run
run and nilesh one two three and continue and you will see our post view hello cloud genius
see this cloud genius is not known to wordpress i modified it our modifications are intact they
did not disappear it stayed that's the key takeaway so persistence the takeaway here is
persistence of data let me describe that one more time you want your machines and things that you
run should persist because disasters will happen persist that persistence is important that
persistence comes as a result of separating data from the container
container that's it nothing much to it whatever data you want to preserve and persist
because the containers will die and come again up and die and come again up and keep on happening
as long as you are keeping the data out away from the container separate in a good location
i will describe what good is in subsequent sessions but keep the data away in a good
you know robust location you are golden you can destroy your containers left and right and doesn't
matter they'll come back again in fact in kubernetes this thing happens by itself if you kill a container
it comes back again by itself you don't even have to run docker compose up like i did here you see
i did docker compose up and it brought back the whole stack in kubernetes you cannot kill a
container even if you kill it doesn't doesn't matter new one pops up automatically that's the
design so that's the idea so that you saw one example now at this moment i should maybe pause
a little bit and ask you questions about what do you think that you that you did not understand
in my demonstration of this this concept of running three containers in a two-tier architecture
with the idea of running something like an application on top the database below it and
and keeping the data relevant data away from this container structure so any questions if you have
go ahead no questions quiet that's okay i don't have to ask questions but you can
but you can so let's go further and i think uh let me let me uh inspect i have a variety of
examples in that same git repo i want to inspect that git repo and see if i can bring up a relevant
example that actually works the way we want it to work in an easier to understand fashion because
you know i can go deeper and nerd out with you with curl and you know insecure and dash i and dash
this it's a never-ending game i i keep going that's not what i want to do i want to give you a
concrete thing that you can take away with you and and play with it and maybe next seven days or so
you show me your own wordpress running on some machine somewhere i don't care where some any
cloud you take any cloud run it you know install take here's a quick trick take a cheap cloud from
some location or maybe a free cloud from many companies give you free stuff so take that like
amazon gives you free stuff google gives you free stuff i think even microsoft does and so basically
for a few days for a few months sometimes a full year they give you free stuff take it use it to
start one machine cheapest one really because i don't want you to burn money so get the cheapest
machine you can find for free install linux on that on on some cloud and install docker on that
and then bring this git repository and say docker compose up like i just showed you what i what you
want to do is go back to the repository that i described again this file was empty to begin with
right so i copied from the three tier wordpress example like that copy the whole thing and put
that in this file and you don't even have to modify line number 26 like i do because i have
a constraint you probably will not have such a constraint in a cloud setup because there's
nothing running to begin with and you bring this whole thing up it should work send me a link
just to tweet tweet me that link after you get it to work like hey here is my cloud running
wordpress with this example so do that i think that is what i want you to consider experimenting
so do stuff as opposed to you know not doing it so basically do it the only way to learn is by doing
there's no other way and that's the takeaway so this is how this is how it should be like port
number 80 on your cloud machine and a simple example you can play with i think will be say
digital ocean that will give you like a free something are they giving free yeah i i'll tweet
out a link they probably give free stuff but if they don't give you amazon will definitely give
you free tier aws.amazon.com slash free should give you some free stuff there we go so they have
the free stuff so take create an account here and let me give you further details on how to keep it
free for one full year so here it comes one full year you can keep it for free as long as you follow
their constraint so what are they telling you they're telling you that you will be not charged
provided you consume 750 hours every month so in a month typically you have like 734 five hours
in a in a given month give or take less than you know basically less than this many hours
so that's good so basically one month free every month for 12 months that's one constraint
the second constraint is that you have to use the cheapest possible machine that amazon sells and
they sell you a t2 micro or t3 micro instance that's what they're showing you in the in this
fine print so let me go back and show you the fine print again here you will see that this thing
oh the thing disappears so t2 micro or t3 micro instance running linux you can get that for free
for one full year so that's the machine you should get don't get any machine bigger than that because
it will cost you money and i don't want you to waste money so spending money great idea wasting
money bad idea don't waste money as you're learning this is a good idea so take a t2 or t3 micro
machine install docker follow the official instructions you will ask me how do i how do
i install docker so here's how you do it you go to the source always go to the source so there'll be
like hundreds of websites giving you how to install this and how to install that don't listen to any
nonsense go straight to the source so go to docker documentation docker documentation on the internet
you will find hundreds of thousands of things that are conflicting with each other how do you
resolve it you don't listen to anybody except the source so here you've got docker reference
and actually the way to search it is docker install ubuntu so there we go so that's how
you install docker on ubuntu so you get a ubuntu instance on t2 micro t3 micro on amazon free tier
for one full year install docker engine like this follow step by step you will have docker
just remember to read carefully and you have a machine running docker then you go to my exercises
here and run through just exactly what i did that you will have a wordpress running to play with this
show it to me and next time what i want to be able to do is improve upon this example to give you a
proper ssl certificate tls certificate provided you have your own domain some of you may not have
so what do we do you need to get a domain getting a domain is not free but very cheap
how do you get a free cheap domain you google search the worst possible site you can get and
this is my opinion so don't take it for for what i'm going to say right now but godaddy sucks
godaddy they're horrible they're horrible site in terms of the user interface
but you know what they're cheap they give you a site a domain name not site sorry i said it wrong
no we don't buy a site from them no please don't get a domain from godaddy or anybody else for
cheap cheap one dollar price sometimes they don't give you a one dollar price right away
right so some random domain.com you search and they might give you something so it's like what's
the price right now one cent oh even better than one dollar here it is take it like yeah absolutely
this kkwhateverdomain.com for one cent absolutely buy it immediately and that's your domain i mean
don't do that what i would recommend actually is get a proper domain with your name because then
you can use it for yourself to make a portfolio for yourself so for example akshay kumar right
we have akshay kumar right here so you should find a domain called akshay kumar and buy it let's go
see akshay kumar.com probably this domain is taken by the movie star domain is taken some other guy
it doesn't look like akshay kumar but that's an idea so you don't want akshay kumar maybe get
something else like with your last name or maybe just akshay or akshay k i don't know probably
taken out as well so yeah it's it's kind of difficult to get the proper name but i got it
this mylastname.com i am i have it so this is available to me uh for last 23 years maybe more
i just have the domain i'm using it occasionally not too much but that's how you buy a domain if
you don't buy if you don't get a cheap cheap domain for like less than a dollar on godaddy
what do you do i'll tell you a trick now what do you do is go to google and search for
a competitor to godaddy something like name cheap name cheap one dollar domain and you
should do these things one after the other so name cheap domain godaddy domain and just just
have the browser register cookies for both these websites and then an ad will pop up like it just
did i can see the ad right there 99 cent domain name registration bingo why did they give you
suddenly a 99 cent domain name because they saw a cookie by godaddy placed on the browser window
and so they're looking at competition and suggesting you a coupon there we go so now
you can search for a domain you like 99 cents or or maybe in your your currency you find a cheap
cheap domain use it for one year at least for the first year first year and before the end
of the year you move it to the at cost domain provider what is an at cost at cost domain
provider what does it mean it means that they don't charge you any fee on top of what is costing
them so the there are certain at cost providers the cheapest ones but they are not cheap the first
year first year is cheapest with these guys godaddy name cheap another other people i have my domains
at a at cost dns provider called cloudflare they are not free to begin with a not like a one dollar
to begin with but they give you at cost cloudflare cloudflare at cost dns so here it is for at cost
domain the pricing is really really with zero markup you can see the orange lip orange flag here
orange line here cloudflare fee they don't charge you any fee on top of what they cost what it costs
to them so whatever the dot com wholesale registry fee is plus the i can fee they don't charge you
anything see that and that's the cost for a dot com domain in reality for other domains it's
slightly different and our cloudflare will soon add other domain top level dnss here but right now
they are limited they're limited to what domains you can get but once you have your own properly
structured domain you can craft out something that is relevant to you for example here is
this
carol george now this guy created a domain and his website and he wrote down his portfolio created
a project site this is the same guy you see on my website he was a boeing employee then over the
years he he kept on working with what what we do at our place and you know he is now a
god knows him some vp somewhere he is 25 years old yeah carol carol george he is what
he's a vp of site reliability engineering at galaxy digital since 2022 just the same guy you
see on my website he worked hard he worked hard basically doing hands-on every single thing he
wanted he did it with me and on his own much of it is on his own but smart guy that's how you should
do so build a portfolio for yourself and learn and show and describe and write about what you're
doing on a post on some post like you know maybe you use the wordpress site on your domain and
start writing posts on your own wordpress blog that you create using the exercise i gave you
that's the idea i hope that is useful to you and i think uh we are reaching the hour mark i'm going
to keep you like waiting longer than expected so we are like about 53 minutes into the conversation
is that right maybe not i don't know how much time has passed i have no idea i lost train of my
thought is it eight o'clock or seven what's the time right now 753 so we crossed the one hour is
it 823 yeah that's more than yeah more than 23 minutes beyond one hour i'm sorry i just lose
i have no sense of time but i absolutely have zero sense of time only thing i remember is when to
start and only i remember when i actually promised somebody that i will start at that time
otherwise i don't even give promises as to when will i start i don't set up appointments that's
why i just do it all you know like there were no appointments like many people ask me for an
appointment and i don't give appointments no not at all because you know when i when i promise
something that i have to do it and i have absolutely zero sense of time because that's
how i work like i have no connection with time or reality or anything i just do what i do and i
enjoy doing and that's it so with that i will give you some time if you have any questions
i will give you some time if you have any questions go ahead and ask otherwise we will
you know stop streaming and continue our private conversation if you have any
if you don't have a question for the public stream i will stop the stream
uh see you guys next time we will run a session like this on a on a building up topic you will
see the the topic list you can see it on the cloud seminar website that's for the next series of
again docker file docker images some more docker we'll also jump into people have asked for
kubernetes we'll do some kubernetes sessions and i'll keep updating this site with every
same time so the same time will be whatever this time is in india it is 8 a.m every wednesday
in the us in seattle time zone it is 7 30 if you are in a different time zone please transfer
this time to that time you know like like you know you know how to transfer times so yeah use this
that's the timing for every weekly session for me it becomes tuesday at 7 30 pm seattle time
every tuesday that means every wednesday 8 a.m we are going to do this session like this
it's a new topic that you will suggest on tweet or any other method of contacting me
and that's the plan we'll keep doing it and until you get tired of it