Docker is a platform for building, running and shipping applications in a consistent manner. With docker we can easily package our applications with everything it needs and run it anywhere. We achieve this Containers, A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.
A Container is an isolated Environment for running an application
Let's get to talk about Containers and Virtual Machines.
Containers VS Virtual Machines
Container: is an isolated Environment for running an application. Containers give us similar Isolation with VMs which allows us to also run multiple apps in isolation. But this time they are more lightweight, all containers on a single Machine share the Operating system of the host machine. Because the Operating system of a container is already on the host a container can start up quickly. Containers also need less hardware resources
Virtual Machine: It as an abstraction of a machine or a physical hardware just as the name implies. For example on your PC you can run 2 OS (Windows and Mac using a tool called Hypervisor: A tool used to create and manage virtual machines e.g Virtual Box and VMware)
So What are the Benefits of building this Virtual Machines: We can run Software Applications in Isolation inside a virtual Machine. Also in a Physical Machine we can have 2 virtual Machines each running 2 different Apps (App1 and App2) with the exact dependencies they need as though they were running locally. So our App1 maybe running Node version 14 and App 2 running Node Version 9. So App1 and App2 are running on the same Machine but different Isolated Environment.
We have some Problems with this VM:
- Must have a flow-blown OS
- Slow to start
- Resource intensive
Docker Architecture
Docker basically uses a client server Architecture. Docker ha a client component that talks to a server component using a REST-API, the server also called the docker Engine is at the background and takes care of running and building applications. Like we said previously containers don't have a flow blown OS rather they run on that of the host. And these containers share the Kernel of the host.
A kernel is more like the Engine in a car, it is the core of an Operating System, it is the part that manages all the part of an Operating system as well as the hardware and Software, like memory and CPU.
Every OS has it's own kernel or Engine with different APIs that's why we can't run a windows application on Linux. Therefore on a linux Machine we can only run Linux containers because of the Application needs to talk to kernel of the underlining OS. However on a windows machine, we can run both Windows and Linux since windows 10 is now shipped with a custom Linux kernel. So on windows we can run both Windows and Linux containers. For Mac OS we use a light weigh Linux Virtual Machine to run linux containers