I'm gonna run one command and watch what happens. Go within seconds.
14 containers spanning three networks created out of thin air an entire
it infrastructure. And in this case,
it's a Cali Lennox hacking lab with 13 vulnerable machines, just like that. Bam,
a Docker, big bang. And then with one command they're gone.
This is the power of Docker compose,
a Docker tool that allows us to build entire dockerized worlds with one file,
saving us on the tedium of creating and running Docker containers line by line
run, Docker run. So in this video,
I'm gonna teach you how to use Docker compose. It's remarkably simple.
And if you're like me, you're gonna kick yourself for not knowing this sooner.
Now there are three things you need to start composing a Docker symphony.
First you'll need just a little bit of Docker knowledge, just a tiny bit.
Like if you've run a Docker container before, you're probably good,
but if you haven't that's okay.
Just watch this video right here and I'll show you everything about then come
back and see me. I'll wait with some coffee, two. You're gonna need some Lennox.
It could be your computer. It could be a VM local in the cloud. W SL two.
I don't care. It doesn't matter. But if you do want to follow along with me,
I'm using the latest version of a BTU desktop inside of virtual box.
And if you wanna build that VM for free, you can watch this video right here,
then finally. And most importantly,
you're gonna need some coffee because everything in it requires coffee,
chuck.coffee. Now, once you're in Lenox land,
let's go ahead and launch our term.
And now let's go ahead and install some Docker compose. We'll do a quick update,
pseudo a PT update to update a repositories little pseudo password action here.
And then with one command I'll install Docker, a PT install, Docker do IO,
and also Docker dash compose.
I'll do a dash Y at the end and quick coffee break. Let it do its thing. Now,
once you have it installed, what do you say? For old time's sake?
We create a Docker container in the old fashioned way. Pseudo Docker run,
we'll name it web, do a few switches.
It D expose some ports and we'll use EngineX as our image, simple,
elegant the way our grandparents used to run it, but old. So what do you say?
We do the same thing, but with Docker compose.
So I'm gonna scoot this out of the way, but I'll keep it viewable right there.
And I'll want to know the terminal. Now,
whenever you're working with Docker composed,
the first thing you wanna do is make a folder dedicated to that one composed
thing you're doing. It'll make sense. Why here in a second.
So let's go ahead and do make DIR and we'll name it coffee time,
and then we'll jump in that directory CD coffee time we're in,
and now let's make our Docker composed file.
And it's just gonna be one file that does everything. It's kind of crazy.
So nano Docker dash compos dot Y AML, two things here real quick.
First, I'm naming it. Docker dash composed dot Y AML,
unless you have a really good reason not to go ahead and name it,
that when you're using Docker compose, it looks for that name by default.
So why even go from that? Just, just do that. And then also notice, uh,
we have the dot YML, which is YAML.
Technically it's a data serialization language. That's too complicated.
Just think about it as a configuration file. It's a nice,
pretty way of writing out configuration.
It's easy for computers to read and it's easy for us to read. You'll see.
It's beautiful. So let's go ahead and jump in that file.
And here is what we'll start to write our symphony, our sweet,
sweet Docker music. The first.
Thing thing we'll do is define the version by simply typing in version colon.
And then right after that, putting in double quotes three,
that's the current Docker version.
You may be watching this in 20 years and we're at Docker version 1220.
I don't know, but it's three right now.
So it's do three then hit enter next we'll define services.
So just type in services, if you can spell it right, lit unlike me hit enter,
and then tab. Now, keep in mind. YAML loves its space.
It needs some personal space, just like Python. So when I say tab,
I mean it under services is where we define our containers.
So I'll just call this guy website, colon, and then enter once more.
And then I'll tab twice, two tabs.
And now I'll start configuring that container first.
Let's do our image type in image, colon. And when we have EngineX that's it.
So just type in, EngineX get that part done. And they're right under there,
keeping the same spacing. We'll do reports. So watch what I do here. Again,
this is YAML stuff, YAML speak tab, tab, tab.
I'll do a dash space and then parentheses I'll specify the port mapping.
So we're doing 80 80,
and actually we'll do 80, 81 80 80 is already taken up right now.
And we'll map that to the port 80 of our container. Now that is it.
we're done. Oh, actually there's one more thing we can do. Let's uh,
tab over to be in line with ports and we'll say restart always.
So it always comes back up after your machine reboot. You want that right? Yes.
Okay. So that's a cap post file, simple, but it'll work.
So let's actually try it out.
I'll do a control X Y enter to save and with one command Docker dash compos
up and then a dash D to put it in the background. That's all we gotta do.
Hit enter pseudo password done. Now a couple of things here.
Notice I ran that command while in that coffee time directory,
the same directory where my composed file lives. Make sure you do that.
If you don't, you'll have to do some dash F and specify where it's gonna,
it's just the whole thing. Just make sure you're in the same directory.
Also notice this. Yeah, it did create my website. It named it coffee time,
underscore website one, which coffee time was the name of my folder.
So that's why that's kind of important.
And then the website being the name of my service,
and then it just puts one after it, like,
assuming you're gonna make more of them,
but then also notice good old Ducker compose made a network for us too.
That's some service.
He created a default bridge network and put our container inside.
What a good guy. And yes, that is the default behavior of Docker composed.
Cuz we didn't do anything differently. You can change that.
And I'll show you here in a bit. Now I do wanna make sure our website works.
Let's go out there actually first we'll do a Docker PS.
There's our two containers and there's 80, 81 right there.
The one we just spun up and actually here, this is kind of cool.
If we do Docker, compose PS,
it'll only show us the Docker containers within that composed environment right
there. That's kind of cool. And let's make sure things work.
Local host port 80, 81. Beautiful. Now like I showed you in the intro,
we can bring down that entire thing with one command and the entire thing.
We have one thing in there right now, we're gonna add more, just hang tight,
but we can do pseudo Docker compose down, down boy. And it just,
it deletes it. In fact they remove the network and the container.
Now we don't have to do that. If we just do another up command here,
bring 'em back up. Instead of down, we can do stop.
Just simply stopping the containers. So you have options.
I wanna do down once more just to delete it.
So what I wanna hit home here right now is that the.
The Docker compos file is simply the Docker run command.
It just looks a little weird. It has a different format.
We have to describe it in a certain way,
but that's really not too difficult with the power of Google.
Just go look at some Docker documentation. We covered the basics here,
but there's obviously a lot more. So go Google it. It's pretty cool,
but don't do it yet.
I'm gonna show you some more stuff because we're about to get a little crazy.
Now. You know what I love about Docker containers. They're safe. They're secure.
They're isolated. Most of the time giving you a bit of security, but you know,
it's not safe.
You your computer because you're not using bit defender total security because
it's face it. You're not living life inside of a Docker container.
You need protection.
You need someone to hold you and tell you that you're safe and that they're
looking out for you and your device and your data and shoot. Look at that.
This is new. Did a breach alert for LinkedIn. Are you on LinkedIn? Well,
there you go. But defender has our backs for protection.
They got you with the anti-virus advanced threat defense.
They're also doing some crazy online threat prevention.
They're doing some cloud-based magic by blocking online threats at the network
level and should anything get through which I doubt it.
They're gonna be scanning your system for vulnerabilities,
but it's not getting through cause they get a firewall going on.
it's crazy.
And then I know many of you wish you would've had this before. It was too late.
Ransomware remediation.
They'll help restore your encrypted files if you get hacked and no,
don't just assume you're safe. Don't just assume you're immune.
Anyone can be hacked. Even me. That's why I had this.
And one of the biggest ways you can be hacked.
This is why I have my employees use this fishing attempts.
I get some anti spam going on and I know my audience.
I know you guys care about privacy.
The defender premium security has your back with safe pay VPN password manager.
And this is pretty cool. Video and audio protection. You're always wondering,
Hey, is someone listening to me? Can they see me on my webcam right now?
They'll make sure they're not.
they'll have that control in place and I'll make sure no one's tracking
you and I'll make sure, Hey, are your kids being a little crazy?
Cuz mine are always being crazy. They'll help me keep track of my kids.
And you don't have to worry about performance with bit defender's profiles.
You can tell them, Hey right now I'm working or Hey, I'm playing a game,
please don't bog down my system.
They'll adjust to what you're doing at the moment.
So you can toggle about yourself or just let them decide.
They probably know better than you. So check out bit defender premium security.
I got a link below. It looks like they're giving us dad gum 10 devices,
one year subscription and 59% discount. Don't miss that because again,
we don't live in Docker containers, even though that does sound kind of awesome.
We don't. So back to Docker composed with our compos file,
we can create just a ton of containers. Like I mentioned before inside.
And also we can create networks so real quick, let's add another container.
Let's just do a duplicate of our engine X container here.
It's gonna copy website here and then making sure I have the correct spacing.
I'll paste it right there. And I'll just rename a few things. Website two,
we'll do a different port,
80, 82 this time and noticing that I'm keeping both these containers under the
services section.
And now we have two containers control X Y enter to save Docker,
compose up dash D two containers, but we're not stopping there.
Let's add a network. Now, if you watch my Docker networking video,
you can watch that right here. Normally to create a network,
you have to run a command like this.
Let's do the same thing inside a Docker compose file, nano Docker, compose.
Dot YAML, and down here underneath our containers.
We'll start a brand new section called networks,
noticing that it will be in line with services. It's a top level config.
And then we'll tab over name, our new network. It was coffee, right?
So we'll do coffee, colon enter tab tab here. It does get a bit different.
We're gonna specify IPAM which stands for IP address management enter tab tab
tab. And now we're at the config. So we'll specify our network driver,
which here will say default, which in Docker,
the default network is the bridge enter tab tab tab. We'll do some config,
colon enter tab tab, tab, tab,
and then we'll specify our subnet inside double quotes.
So that right there is how you take that Docker command. And yeah,
there's some left over here on the side. Sorry guys forgot about you.
Let's how you take that command and convert it into Docker composed YAML.
Not too bad, actually. You just have to kind of know it. And then finally,
one more thing. What do you say?
We throw one of those containers inside that network.
Cause right now it won't happen.
So let's take website two just under his restart. I'll add networks,
colon enter tab, tab, tab.
I'll specify the network coffee and then his I P D four underscore address.
I wanna say 1 92, 1 68. What was that network? 40. Yeah. Or 92 92.
We'll do do like 21. So now with our composed file,
we're creating two containers. One network let's save it and test it out.
Control X Y enter to save Docker,
compose up dash D let's watch the magic happen. That was fast.
Now notice something here. We already had our composed file up and running.
But here, when we changed the file and we ran the Docker composed up command,
once more, it just updated what we changed.
It created that new network and it recreated website two. So let's take a look.
We'll do Docker composed PS. There they are. We'll do a Docker network LS.
There's our two composed networks. One by default one we specified.
And then if we inspect our new network, Docker, inspects, if I spell it right,
I can see that container inside right there with the IP address we configured.
Okay, cool. So we've done two containers and a network, but what do you say?
We get just a little bit crazier and this will uncover the true power of Docker
compose because our next task, I'm gonna clear this out for you.
We're gonna deploy word press with Docker compose.
Now here's why you would wanna use compose with WordPress.
WordPress has two main components.
It has a front end website or a front end server and it has a myse database and
in a Docker deployment,
that'll be two separate containers and this'll be a bit different because
there's something special that'll have to do to connect these two guys to make
them kind of well connect and work. Let's try it real quick.
So actually let's go ahead and make a new brand new composed file.
So let's cd.do to get out of that directory and let's make a new one.
M K D I R WordPress. Let's jump in there.
N dock composed dot Yammel. We are in now.
Same stories before we'll define our version. Good oh three.
And we'll start with our services defining our two containers we need for
WordPress. First, we'll start with WordPress.
We'll call him WordPress and for our image,
we'll simply pull the WordPress image from Docker hub for port we'll map,
port 80 to 80 80 on our machine. Actually,
now we need to do something else don't we let's do like 80, 89 because I forgot
where we were. And the next is something interesting.
We're gonna have something called environment and here we'll put specific
parameters that are specific to WordPress inside the WordPress environment.
Let me go ahead and paste a few right here.
You can copy the code from below as well. Noticing here,
we have things that are specific to WordPress.
Like all the database info we can pass those environment variables into
WordPress as we're creating a container.
And pretty much every one of these are referencing what we're about to do with a
SQL server or a my SQL server. Sorry, my SQL. So we'll go ahead and add our,
my SQL server. We'll call that service.
My SQL the image will be my SQL colon five seven,
and I'll put that between quotes and then we'll also do some environment
variables for him.
So now we're seeing that WordPress is matching the SQL service as his database,
the password as coffee and the database name as WordPress.
Now a couple of cool things we can do with containers and how they interact.
First up here in WordPress, let's add another parameter.
Then we'll call this depends underscore on colon.
I wanna enter a couple tabs and we'll tell it to depend on my sequel.
And this is cool. Cuz what this will do is tell Docker compose, Hey,
before you make this WordPress container, even if he is the first guy up here,
make sure you make the mye guy first because WordPress depends on him.
So you can tell him to do that. That's kind of neat.
So don't make him until you've made him.
And one more cool thing you might wanna add to your WordPress deployment,
cuz you could legit just run your WordPress website inside Docker like this,
but here on the MySQL container,
let's add one more section and we'll call this volumes and Docker volumes allow
us to map a Docker directory to a directory on our system,
on the host system. That way if the Docker container ever gets blown up,
dies or restart it, delete it, whatever that directory,
the data still exists on the host, which is kind of important for a, you know,
database. So we can simply map it like this, telling it Hey,
in this current directory,
go ahead and create a volume called my SQL and map that to inside the container
VA lib my SQL, which is what my SQL cares about. Now this will work beautifully,
but I do wanna go through the trouble of adding a network.
If you know how to do that, if you remember how to do that,
go ahead and do it right now. Cause I don't want Docker creating that for me.
I wanna do it myself. Call it. Oh yeah.
And then I'll add those containers to the network.
So there's our completed Docker composed file right here. Isn't she pretty?
So let's control X Y enter to save. Now let's bring that bad boy up. Docker,
compose up dash D.
It's gonna download all the things it needs for WordPress in my sequel.
It'll take a second quick coffee break.
This feels like a magic when it's doing that. I love it. And just like that,
we get a WordPress website running. I'll do a little doctor, compose PS.
Oh not compo, compose PS. There they are. Let's see if we can get to it.
Local host port 80, 89. Yes.
WordPress website. That's so cool. And also notice if I do an LS right here.
There's that mye folder. That's where my SQL is mapped. I jump in there.
There's all my SQL goodies.
So if I were to do a pseudo Docker compose down,
so tear it down and delete it. I still have my database intact,
which means bringing it back up. Yeah. It's creating brand new things,
but sequel is still in mapping to that same database file.
And if I refresh the page, same stinking website, that's pretty cool.
Now of course you can deploy that lab. I showed you earlier.
If I did that right now, I'll see hacking lap. My new directory.
I'll start my Docker composed file. And I'll just paste all that in there.
It's a lot, but you'll notice that it looks.
Familiar. We've already talked about a lot of this.
It's just a bunch of networks and a bunch of containers all connected together
in various ways. By the way. Yes.
All of these are vulnerable containers from a place called VUB not
V hub V hub. They basically turn V hub, uh, virtual machines into containers.
So shout out to them. I'll put a GitHub link below.
And of course also right here, I have my Cali Lennox machine,
which is cool because once I launch this, go ahead and do it right now.
That's gonna take a minute. Cause it has to download all those, uh,
container images. So while that's downloading, it might take a minute for you.
It's taking a minute for me. Here's some Docker, compose inspiration, cuz again,
companies mainly use Docker compose to deploy their apps cuz they can kind of
package them together. Make sure they're connected the right way.
So things like, uh, I guess you can do Minecraft,
which all it does is define a volume and an image, but more complex things like,
um, pie hole with CloudFlare DOH, bam.
So I'll put this link below for some inspiration. Lemme check on my stuff, man.
Still downloading. Oh my gosh.
So Ducker post knowing it not only makes you awesome,
but it unlocks the door to a ton of fun projects and just knowing Docker better
moving from creating Docker containers with simple run commands,
run Docker run to deploying actual dockerized apps. Oh, okay.
Finally done. So I can jump into, uh, my Kelly Lenox box. Haha. I'm in,
let's install in that me update it first and I can start hacking away.
So that's the video.
Thank you for taking time to have some coffee with me and talk some Docker.
It's my favorite thing to do. And by the way,
have you hacked the YouTube algorithm today?
Let's make sure you do with that like button notification, bill comment.
Subscribe. You gotta hack YouTube today. Ethically of course. Yeah.
That's all I got. I'll catch you guys next time.