Under the hood Docker

Virtualization

Yuvraj
Yuvraj
Jul 30, 2017 · 4 min read

The virtualization method can be categorised based on how it mimics hardware to a guest operating system and emulates guest operating environment. There are 3 types of virtualization.

  • Emulation
  • Paravirtualization
  • Container-based virtualization

Emulation : Emulation, also known as full virtualization runs the virtual machine OS kernel entirely in software. The hypervisor used in this type is known as Type 2 hypervisor. It is installed on the top of host operating system which is responsible for translating guest OS kernel code to software instructions. The downside of this type of virtualization is additional system resource overhead that leads to decrease in performance compared to other types of virtualizations.

Examples in this category include VMware Player, VirtualBox, QEMU, Bochs, Parallels, etc.

Paravirtualization : Paravirtualization, also known as Type 1 hypervisor, runs directly on the hardware, or “bare-metal”, and provides virtualization services directly to the virtual machines running on it. It helps the operating system, the virtualized hardware, and the real hardware to collaborate to achieve optimal performance. These hypervisors typically have a rather small footprint and do not, themselves, require extensive resources

Examples in this category include Xen, KVM, etc.

Container-based virtualization :Container-based virtualization, also know as operating system-level virtualization, enables multiple isolated executions within a single operating system kernel. It has the best possible performance and density and features dynamic resource management. The isolated virtual execution environment provided by this type of virtualization is called container and can be viewed as a traced group of processes.

Examples in this category include LXC,libcontainer

Why Containers ?

1 Unlike a virtual machine, a container does not need to boot the operating system kernel, so containers can be created in less than a second.

2 Since container-based virtualization adds little or no overhead to the host machine, container-based virtualization has near-native performance

3 All containers on a host machine share the scheduler of the host machine saving need of extra resources.

4 Container states (Docker or LXC images) are small in size compared to virtual machine images, so container images are easy to distribute.

And many more

what is Docker ?

Companies use Docker to run and manage apps side-by-side in isolated containers to get better compute density.

docker is lightweight and uses LXC/libcontainer ( They start with LXC and latter they develope their own container runtime libcontainer ) and does not have machine/hardware emulation such as hypervisor, KVM and Xen which are heavy. Lets go deeper

Docker start:

Let’s check what is docker image.

docker save --output /temp/ubuntu.tar ubuntu

mkdir test

cd test

tar cvf /tar/ubuntu.tar

ls

You got some hash dir they are layers. They follow tree structure to form that environment.

Let’s do some crazyiyapa

docker run -it --name my-image ubuntu

docker exec -it my-image /bin/bash

#now you are inside docker container

apt-get install apache2

#do some installation.you can create your environment and exit from container and check container id by docker ps

docker commit 'container id' image_name:latest(replace image_name with any name.choose it according to your convenience)

# check docker images you found your image name

docker save --output /temp/new_ubuntu.tar image_name:latest

mkdir environment
cd environment

tar cvf /temp/new_ubuntu.tar

#check hashes count before installation in test folder and after installation. You found different number. In installation you just create some node in the tree in form of hash. That’s docker images.We can reuse these layers they store in cache.

Now talk about containers. Container is a process controlled by cgroups and namespace.

What is cgroups and namespace ?

They help to controlle a process in terms of storage,network,cpus etc. They are responsible to manage process in your os. When we create a container meaning we create a process who has its own world and controlled by cgroups and namespace.

So what the fuck docker do ?

docker is just a run time who help us to manage things easily.

What is docker file ?

We just create our docker image by container commit. It’s a manual process on production we can’t do manual things.

Docker file is the solution. It also help us to create same environment on any system but how it work?

Docker provide some command (API) like FROM,ADD,RUN,COPY, etc

They tell docker client to exec some instructions. For example

FROM : Path of base image (ubuntu)

RUN apt-get install apache2#help is to run command

By using that file you can setup your environment in any system. On production it help us a lot.

docker build (help us to create container using docker file)

Docker world is a bidirectional

container <-> image <- Docker File

When you install docker you got a docker host and client.

What is Kuberneres ?

Kubernetes is an open source container orchestration framework built by teams at Google and bases its container-worldview on how Google develops within their walls in Mountain View.

Kubernetes vs docker ??

Above part about docker only help us to work on single node. But on production we use cluster. Cluster size depends upon situation traffic.

And by the way comparing Kubernete vs Docker really comes down to comparing Kubernetes to Docker’s Swarm product

Docker Swarm (Next Post)

Resources : Play Ground Docker (Beginner can start from here)

Yuvraj

Written by

Yuvraj

evalsocket.com - Dark side of bright

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade