Docker
Introduction
Before VMs, every server only had one operating system. This means if you wanted a windows server and linux server. You needed two physical servers. Here comes virtualization, instead of installing an OS you install a hypervisor (VMware ESXi). This allows you to divide your server resources into multiple servers running different OS.
Hypervisor Flow
Well why use Docker to run different OS on your server if hypervisors do that already? Well, virtualization and virtual machines virtualize hardware. Docker visualizes the operating system.
Docker Flow
The docker containers contain the OS that we need to run. These are micro containers that contain their own OS, CPU, Memory and Network. These are lightweight, fast and isolated.
Why is it so fast?
Since we are building our docker engine on top of our linux server. We only need one kernel. All Docker containers use the same kernel. As opposed to, hypervisors which contain their own kernels.
How is the industry using Docker?
Developers can write their code. Deploy it in a docker container, and it works anywhere.
Microservices
Take portions of your stack and segmenting it into smaller bits and pieces. Split your app server, app client and database in separate containers.
Dockers in Node
Dockerfile is a blueprint for building a Docker Image
A Docker Image is a template for running Docker Containers.
A Container is just a running process.
- Developer creating the software defines the environment with the dockerfile.
- Another developer can use the docker file to rebuild the environment which is saved as an image. Images can be shared and anyone can pull that image.
- The image can be run in a docker container
Creating a Dockerfile that Creates Docker Image
Create Docker Ignore and add node_modules
Create Docker Image
The period is the path. When the process is done. It returns "successfully built image_id"
Next you can push this to the cloud for others to use. For now we are gonna, run the docker locally.