So now we know what Docker is
and what containers are and why we might wanna use it.
We will learn what exactly Kubernetes is a little bit later
in the course, by the way.
But let's stick at the basics for now.
Containers and Docker.
The problems solved by Docker
and containers makes sense hopefully
and it makes sense that we might be looking
for a solution like Docker and containers
but if you've been in the software development area
for some time, you might also think to yourselves
why Docker and why containers?
Isn't that a problem?
So that reproducible environment thing,
isn't that a problem which we can solve
with virtual machines?
So machines running on our machines?
Virtual machines with virtual operating systems encapsulated
in their own shell independent
from our host operating system,
isn't that a solution?
Well, kind of.
With virtual machines,
we have our host operating system,
Windows or macOS or Linux
and then on top of that, we install the virtual machine.
So a computer inside of our computer so to say.
This virtual machine has its own operating system,
the virtual operating system,
which runs inside of that virtual machine.
Let's say Linux.
Then in this virtual machine,
since it is like a computer,
it's just virtually emulated you could say,
but inside of that virtual machine,
we can then install extra tools.
We can install whatever we want in there
because it is just another machine,
even though it just exists virtually.
We can install all the libraries, dependencies
and tools which we need
and then also, move our source code there.
And hence, since it's an encapsulated virtual machine
with everything our program needs
and all the tools being installed there,
we kind of have the same result
as with Docker and containers.
We have an encapsulated environment
where everything is locked in.
And we could then have multiple such environments
for different projects
or we could share our virtual machine configuration
with a colleague to ensure
that we're working in the same environment.
Well, this works but there are a couple of problems.
One of the biggest problems is the virtual operating system
and in general,
the overhead we have with multiple virtual machines.
Every virtual machine is really like a standalone computer,
a standalone machine running on top of our machine.
And therefore, if we have multiple such machines especially,
we have a lot of wasted space and resources
because every time a brand new computer has
to be set up inside of our machine
and that, of course, eats up memory, CPU
and of course, also space on our hard drive.
And that really can become a problem
if you have more and more virtual machines on your system.
Because if you have a lot of things,
which are always the same
and still duplicated, especially the operating system.
You might be using Linux in all your virtual machines
and still it's installed separately in every machine.
And that, of course, wastes a lot of space.
In addition, you might have a lot
of other tools installed in every virtual machine,
which your application doesn't need directly
but which still are set up as a default.
And that can be a problem.
So to sum it up,
virtual machines have a couple of pros and cons.
They do allow us to create separated environments
and we can have environment-specific configurations in them
and we can share and reproduce everything reliably
but we do have this redundant duplication,
that wasted space.
Performance can be bad
since we have an extra machine running on top
of our host system
and especially if we have multiple such machines,
performance can really degrade.
And in addition, even though it is reproducible
and sharable, that also can be tricky
because if you still have to set up that virtual machine
on every system where you want it
and you have to then configure it in exactly the same way.
There is no single config file you can necessarily share.
If you wanna deploy your application,
so from development to production,
you also have to ensure
that you configure your production machine
in the same way as your virtual machine.
Alternatively, you run your virtual machine
on your production machine
but that wasted performance,
that's something you might not wanna do in production.
So it solves the problem but not in a perfect way.
And you might guess
that's why we have Docker and containers.
And actually, it's really important to understand
that containers is the key concept here.
Docker is just the defacto standard tool
for creating and managing them.
So why does Docker help us with that?
How do containers solve that problem in a better way
than virtual machines do?
With containers, we still have our host operating system,
Windows, macOS, Linux, whatever it is
but then we don't install a couple of machines
in the machine.
Instead, we utilize built-in container support,
which our operating system has
or emulated container support,
something Docker will take care about that this works.
And then we run a tool called the Docker Engine
on top of that.
And that will all be set up by Docker
when we install it, by the way.
And then, based on that Docker Engine,
which now runs on our system,
which is just one tool,
one lightweight small tool being installed there,
we can spin up containers.
And these containers contain our code
and the crucial tools and runtimes our code needs,
like Node.js, for example,
but they don't container a bloated operating system,
tons of extra tools or anything like that.
They might have a small operating system layer
inside of the container
but even that will be a very lightweight version
of an operating system,
much smaller than anything you would install
in a virtual machine.
And you're going to see how containers work exactly
and how you create them throughout this course, of course.
Now, the other great thing about containers
is that you can configure and describe them
with a configuration file
and you can then share that file with others
so that they can recreate the container
or you can also build the container into something,
which is called an image,
which you need to do anyways
and then you can share that image
with others to ensure that everyone's able
to launch that same container which you have
on your system on their systems.
And obviously, we're going to dive in detail into images
and containers throughout this course,
so you are going to learn all about that step by step.
So if we compare containers to virtual machines,
we have a couple of advantages on the container side.
They have a low impact on our operating system and machine.
They've very fast.
And they use minimal disk space,
sharing, rebuilding and distributing them
is very, very easy
because we have these images
and these configuration files.
And we still have encapsulated apps and environments
with everything our app needs but nothing more,
which is perfect, which is exactly what we want.
Virtual machines, on the other hand,
have that bigger impact on your operating system.
They tend to be slower
and they also tend to eat up more of our disk space.
In addition, as I said, sharing, rebuilding
and distribution, that all can be done
but also may be trickier than with containers and Dockers.
Still, of course, we encapsulate our environments
but we don't just encapsulate our app
and what it needs to run but entire computers.
It's like having a totally separate machine,
which in rare examples, or in rare uses cases,
could be an advantage but often,
it's just a bloated thing, which you don't necessarily need.