Check out a free preview of the full Complete Intro to Containers (feat. Docker) course

The "Containers" Lesson is part of the full, Complete Intro to Containers (feat. Docker) course featured in this preview video. Here's what you'd learn in this lesson:

Brian gives a brief history of why containers are useful tools that host controlled and isolated environments, thanks to a frozen file system. The latter allowed engineers to have access to ready to use containers without having to recreate all the dependencies and file system on a local machine.


Transcript from the "Containers" Lesson

>> What are containers? So that's probably more simple than some of you may think. Some of you might already know this, the answer to this question. But there's actually no such thing, one single thing that is a Linux container, right? We like to have this idea that a container is this, we say, all right, Linux, containerify that and it just works, right?

And it's not quite that simple. A Linux container really is actually a combination of at least three different kernel features within Linux. That kind of culminate in this idea of what a container is. And again, this is gonna be all here in the command line. So if you have any issues with it, go ahead and check out Jem's course on it.

It's a great course. So, Before we kinda start getting into what is a container, I'm going to give you a little bit the history of why we need containers, right? Kind of lead you through the journey of how we got to where we are today. So I want you to picture for a moment that you are head of a engineering team at a big corporation, right?

And you need to host your website somewhere. I don't know how you became a head of engineering with no website already. But this is the situation that we find ourselves in for this hypothetical, okay? So if you had been 15 years ago, or 20 years ago, doing this, you should start thinking about, all right, well, I need to buy a bunch of servers.

And I need to figure out where my data center's gonna go. And I need to hire a bunch of people that are gonna manage racking and stacking servers, stuff like that. As I call it here, you're working with the bare metal, right? So you're actually going to Dell, you're going to EMC.

You're going to some of these really big cloud providers. Or not cloud providers, but hardware providers and saying I need x amount of servers and I need these kind of things. And then you have to worry about physical security, the data center. You have to worry about the temperature.

You have to worry about upgrading things that that are no longer powerful enough. You have to worry about all sorts of stuff like this. For me, the developer that just wants to sit here and write my JavaScripts all day, that sounds like something I very much do not wanna do, right?

There are trade-offs here, right? There are still reasons that people do this, right? There are still lots of company running on bare metal. I imagine many of your companies are still running on bare metal servers, right? It's more secure, right? Because you are not sharing anything with anyone, right?

You control everything. You control your entire destiny. If you have these economies of scale, it can be cheaper for you, right, than doing something in the public cloud. And if you have anything that's extremely performance sensitive, you can tune your boxes to be as whatever you need out of them.

But it comes with a lot of problems, this is expensive, right? You have to buy more capacity than you can use, right? Because if you're hitting your capacity, that means that you're dropping stuff on the floor, which means that you always have to have more capacity than you're using.

And a lot of has seasonality to our apps, right? So if you have enough capacity to handle Singles Day or Black Friday, that means you have a bunch of service just sitting idle the rest of the year, right? You have to worry about stuff breaking, right? Sometimes RAM just goes bad, right?

And then you have to go in and fix that. That's also still your problem now. And let's say you need to buy more capacity, right? It's not like where you can just say, hey, Kubernetes, give me another node, right? And you just have one. You have to call up Dell again and say hey, I need more servers, right?

I actually thought about writing a Kubernetes provisioner that made a purchase request, right? And then eventually when it comes back and comes online, then it spins up your node, right? That's the worst idea. It would be terribly expensive and that's why I have not written it. I also don't have enough money to do that.

So, Yeah, that only takes a month or two, right? It's pretty much instant. [LAUGH] So hopefully you're getting the point now. Bare metal has its ups, right? But it has a lot of downsides. There's a reason why a lot of companies don't do bare metal service anymore. So let's get down into virtual machines then.

So if I have a Web server, I'm running it on one server blade within my data farm, right? I'm running everything on bare metal operating systems like that. Well, what would be really cool is I could actually just have a farm of server and then I could have an arbitrary amount of servers running on them, right?

And that's kind of where virtual machines come into the picture, right? So I can have one server but I can have multiple different operating systems running at the same time as virtual machines, right? They're virtual servers, in that sense. And that gets to be very helpful because now I can scale up and scale down within my capacity of my data center, right?

And that that's helpful because then I just have to manage capacity. Cuz if I have one team go offline, they take down their service, I can then reclaim that immediately and add more stuff to it, right from this other team that's coming online, right? So this kind of virtualization strategy allows us to separate VMs, right?

At this point, we're still having to manage our own hardware and we still have to manage our operating systems, and drivers, and all that kinda stuff. But, at least, we can scale up and kinda scale down within our own capacity. So, let's talk about something else that this solves for us.

Let's say that now we're running a hosting provider, right? Some sort of shared hosting provider. Let's say I had two different clients and I just dropped them both with root access to the same computer. And they're just say, all right, now run your servers. Now if you're skin is starting to crawl, good.

It means that you already understand some of this, right? But if your skin's not crawling, let me make it crawl for you. So let's imagine that you have two sort of providers. Let's say one them's name is Coca-Cola and one of them's name is Pepsi, right? And Coca-Cola decides to store on their server recipe.txt, right?

Now, hopefully you can see what I'm getting at here. If we have Pepsi on the same server, they could just change directory over into Coca-Cola's directory and say secret recipe. I got it, great. I don't know why I made Pepsi the bad guy in this situation. But they're definitely the bad guy, right?

[LAUGH] All right, so this ends up being not great, right? So that's why virtualization can also help too because now they're in different operating systems. They can't even see each other, right? They don't even know that they're on the same server. To them they just, all right, here's a copy of Ubuntu.

You're just chilling out on Ubuntu and that's it, right? We still have problems here though, right? If I if I'm running a hosting provider and Coca-Cola and Pepsi are on VMs on the same computer, well, if I'm Pepsi I can just say run a fork bomb within my particular VM.

Which consumes all of the resources, and CPU, and memory, and all that kinda stuff. And it would take down the server and it would take down everyone on the server, right? So that way they could cause downtime for Coca-Cola and that would be a big problem. And much less nefarious than someone dropping a fork bomb, if you haven't heard of a fork bomb I dropped a link in there.

It's a little short command that just takes down an entire system almost immediately. It's kinda fun. Don't run it on your own computer. [LAUGH] But yeah, much less nefariously, you cannot just have someone that wrote a bug that leaked memory and took down the entire server. And you want them to just take themselves down.

You don't want them to take down everybody, right? So that's kind of we still have a problem here by just having the same people on VMs. Now, with VMs, as you may guess, you can also limit how much. All right, you only get this many cores, you only get this much RAM.

And you can kind of mitigate some of those solutions. But I'm gonna show you how to do that even more with something called C groups. So we still have a bit of a performance problem here, as well. It's not, let's say that I have ten servers running as VMs all within one racked server in my data center.

But we still have some overhead here that's making this still an inefficient system, right? We have to run ten copies of, if we have a server that's running ten different, a silicon server that's running ten different Web services, right? We still have to run ten copies of an operating system.

And we're wasting some of that capacity on ten copies of the operating system. It would be great if we could just run one copy to the operating system, right? So this is what I'm hinting at with containers here. So again, if you want to play with VMs directly, Jem's course does that.

And VMs are still very much a very valid option. I know a lot of people out there are still using Azure VMs and AWS, EC2, right? Very, very valid things still to be using, and there's still reasons that you want to use VMs. And so you should definitely play around with those as well.

And like I said, Jem's course on Frontend Master does that for you. So I think he goes out and plays out with DigitalOcean. Okay, so that brings us to the public cloud kind of situation, right? So this is gonna be Microsoft Azure, Amazon Web Services, Google Cloud Platform.

Which you'll often hear me saying GCP and AWS, because I work in the business and I cannot help myself but use acronyms. I'm sorry. [LAUGH] they've taken me. So this is great because now I've moved the data center away from my particular company, right? I no longer have to have these admins.

I don't have to buy physical space. And I don't have to worry about temperatures or anything like that. I just say hey, Amazon Web Services, or hey, Microsoft Azure, give me another VM and let me provision something. And those companies have massive data centers all over the world, each one of them has like 30 or 40 different regions.

So that's really great. We get the economies of scale here and I just pay them for the spinning the meter of how much CPU I'm using, how much memory I'm using. And they handle all those service for me. They handle updating the hardware. You never have to worry about hardware basically ever again.

Now if you're still using VMs, you still have to worry about the operating system, right? They give you the server. But if there's a big security vulnerability, you have to patch it, right? You have to go in there and say Ubuntu, upgrade to the latest LTS or something like that.

LTS stands for long term service, I think?
>> Support.
>> Support, thank you, long term support. Yeah, and that just means that's a version that they maintain for a very long time. So public cloud, this is great. You end up paying perhaps a bit more than you would have if you're running it yourself.

But the trade-off here is you no longer have to hire people. And people are usually very expensive, right? To manage physical data centers, right? So that's kinda the trade off. Usually, it's almost always a good idea to be in the public cloud for that reason. It's usually cheaper from the human perspective.

And it's getting to the point now that a front end engineer can manage their own servers, right? Which would have never been possible 15 years ago. So in these kinda situations tools like Terraform, Chef, Puppet, Salt, things that we won't be talking about today. Cuz I don't know them and you don't wanna learn them from me.

These will be useful because this allows you to spin up servers, provision them. And when I say the term provision, what I mean is install the correct software. Make sure everything's up to date, download your code, start running the code, all that kinda stuff. That's where these tools can be super useful for you.

Definitely check them out if that's something that you're interested in doing. But we're still paying the cost of running a whole operating system in the cloud. And we still have to manage the operating system. It would be nice if we could just say here's our code. Here's the environment it needs, execute this, right?

Here's this artifact of some variety, execute this. And that brings us to the idea of containers. Containers give us all of these security features and all these resource management features of virtual machines. But they're much lighter weight, which is a term that I hate but I'm still gonna use here because it's a absolutely meaningless term, right?

What is lightweight and compared to what? I feel like every JavaScript framework comes out is lightweight, right? [LAUGH] It's the worst. And but here I actually mean it, right? You can say for sure that a virtual machine is lighter weight than running bare metal servers. And the containers are lighter weight than running a whole virtual machine.

So basically what I'm doing is I'm just freezing a file system. I'm dumping that into a container image. And then I'm shifting that off, and then I have some sort of host operating system that's executing these containers for me. So you're still gonna have multiple things running in one host container system, right?

And we kinda have this same worry about the Coca-Cola Pepsi problem that I'm gonna be running this container and then, next to me, another container's gonna be running. And I don't know whose it is or what it's doing, right? So I have these same, similar concerns but let me assure you that with the features of containers, they can't see each other.

They can't interact with each other. They can't even know that each other are there. And a lot of very smart people have been working on this for a very long time. And I feel pretty confident in saying this is secure and you should definitely go down this path.

It didn't always used to be that way. It is now that way.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now