Today, I am going to take technology which creates a hype around the world. People are still exploring Docker and not much aware about Docker. So I hope this article will give you the good amount of details about the Docker. I will make sure you can easily understand Docker and how simple things it is. You might heard that Docker is very complex so this article will make you think that Docker is really simple and you start thinking that Docker is very easy to play around with it.
Docker is prominent so that any image can be transferred easily. Docker plays the excellent role for microservices site.Docker is very good for network administrator and developer both to use.Most of the limitation of virtual machine overcome with Docker.
There is some basic prerequisite for Docker learning and it’s very simple.
- No Docker Experience required: You don’t require to be expert in Docker. You can start with basic understanding.
- You require Linux Machine (CentOS with Kernel > 3.10.0.-327) or Amazon EC2 (If you have slow Internet Connection) – Amazon gives platform for the Docker Or Any Cloud instance
- Be familiar with the Linux command: If you know the fundamental command of Linux, you can easily use the Docker. Docker can be used with executing some Linux command.
Agenda of this article:
- What is Docker?
- Containers VS Virtual Machine
- Docker platform overview and Terminology
- Docker Engine
What is Docker?
Docker is lightweight, an open source platform for an advanced container-based engine. Its source code is hosted on GitHub which is based on the Go language development and to comply with Apache 2.0 open source protocol.
There are lots of things in the Docker.We will discuss most important topics in this article. Docker encapsulates any payload and it’s dependencies.
Docker platform consists of multiple products and tools:
- Docker Engine
- Docker Hub
- Docker Machine
- Docker Swarm
- Docker Compose
Docker works on Virtual Machines, OpenStack, bare metal without any modification.It performs standard operations to start,stop and run etc.Docker supported by many companies, for example,Redhat, Google, Microsoft etc.
A History of Docker
Docker is Docker.Inc company based on the open source technology mainly build the container Engine. To reduce the environmental management complexity, Docker was introduced.Docker can simplify deployment of multiple applications such as Web applications, background applications, database applications, large data applications etc.
This is old monolithic server and operating system and now still running some servers/desktop on them:
Problems in this server:
- Slow deployment times: If you want to deploy from server, it takes times to deploy which increase the maintenance mode or down time.
- Huge costs: sometime cost is very high which is not meet all requirement.
- Wasted Resources: If i know only going to use 10% of resources but i slightly more to safeguard myself to have 90% of resources.
- Difficult to scale: If you want to scale, there might have long down time.
- Difficult to migrate It’s difficult to migrate from one system to another.
- Vendor lock in: Vendor lock in creates barries to the monolithic application.
Let’s understand the virtualization which slightly advanced level to learn. Most of the people now know how to deploy on virtual Machine There are benefits of Virtual Machine.Virtualization is One physical server can contain multiple application.
Each application runs in a VM( Virtual Machine).Docker is a core operating system-level virtualization method.
Let’s understand the benefits of Virtual Machine than the physical system.
Benefits of Virtual Machines
- Better resource pooling: You can say better resource utilization.
- Easier to scale: It’s very easy to scale when to require.
- VM on the cloud
- Rapid Elasticity
- Pay as you go model
If you want to learn more about virtualization of hardware, you can use google or amazon cloud service for an experiment.
Now, I will show you the limitation of Virtual Machine.
Limitations of Virtual Machines
Some limitation Virtual Machines have and here is the list of it:
- Each Virtual Machine still requires
- CPU allocation
- An entire guest Operating System
- The more Virtual Machine’s you run, the more resources you need.
- Guest OS means wasted resources. Even though you run multiple application and have to run same operation system again and again.
- Application Portability not guaranteed: You can migrate complete operation system but application migration is not supported.
Introduction of Containers:
Compare to Virtual technology, Each guest instance is called container. The container is kind of file system.
What actually container is, It is a root file system which has some processes,some memory allocation ,some device and network ports.
Container based virtualization uses the kernel on the host’s operating system to run multiple guest instances.
Each guest instance is called container. Each container has it’s own:
- Root File System
- Network Ports
We don’t have operation system here and this is what container is. Linux container is the bulk of Linux is there but some process isolation is not there and also Namespace is not implemented very well.
The physical system hosts the operating system and hypervisor which provide the virtual machine.Ultimately, Libcontainer library will contain all containers so you don’t require the operating system.Kubernete is one the best to tool to handle the multiple Dockers.
Containers VS Virtual Machines
Here is the list of difference between Containers and Virtual Machines:
- Containers are more lightweight : If you start the virtual machine,it requires at least 2-3 mins depend on application or system you are using but Containers require only 1 second to start and ready to deliver.
- No need to install guest Operating System in Containers.
- Less CPU, RAM, Storage Space required.
- More containers per machine than Virtual Machines
- Greater Portability.
So this is what Docker is different than the virtual machine.
Docker and the Linux Kernel:
Docker Engine is the program that enables containers to be built,shipped and runs.
Docker Engine uses Linux kernel namespaces and control groups.Namespace gives the isolated WorkSpace.
How to install Docker?
Follow the instructions at https://docs.docker.com/engine/installation/ to install the latest Docker maintained docker package on your preferred Operating System.
Run the hello-world container to debug your installation.Here is the command used in Linux.
sudo docker run hello-world.
After installation, you can run this command to check your installation is perfect!
Now, Add the user account to the docker group.The command used to add the docker group is:
sudo usermod -aG docker
Now, Logout from terminal and log in back for the changes to take effect.Verify that you can run the hello-world container without using the sudo docker run hello-world.
Docker client and Daemon:
It’s a client-server architecture. Here, Client takes the input from the user and send them to the Daemon.Now Daemon builds ,runs and distributes the containers.
Client and Daemon can run on the same host or on different hosts.CLI client and GUI(kitematic).
Docker Containers and Images?
Docker maintains lots of images in the registry when to use any docker,pull the image and directly run the image. It will kind of application you are running.
- Read only templates used to create controllers
- Built by you or other Docker users
- Stored in the Docker Hub or your local repository.
- Isolated application platform
- Contains everything needed to run your application
- Based on one or more images.
Docker Hub is the public registry that contains a large number of images available for your use.Docker Hub represented by the Index and Registry. Index Save Image Layer of hash,relationships, and other Metadata. Registry is for the actual binary data stored in the Image Layer.Docker Hub is the world’s largest Docker Registry.
There are three tools for orchestration distributed applications with the Docker.Here is the list of all three tools:
- Docker Machine: Docker machine is the tool that provisions Docker hosts and installs the Docker Engine on them.
- Docker Swarm: Docker Swarm clusters the many engines and schedules containers.
- Docker Compose: Docker composes tool used to create and manage multi-container applications.
Benefits of Docker:
- Separation of concerns :
Developer focuses on building their apps.System admin focuses on deployment.The developer can focus of development and system admin can focus on deployment.Development and deployment both handled separately which decrease the headache of developer and admin both.
- Fast development Cycle:
Nowadays, Continuous integration and continuous development(CRCD) which helps the container to deploy very fast. For example, Google has lots of updates without downtime.
- Application Portability:
You can build an application in one environment and easily ship to another environment.
Scalability: You can easily spin up new containers if needed.
- Run more apps on one host machine: You can run more than one application in one host machine.
Introduction of Images in Docker:
Images in Docker are specified by the repository:tag. The same images may have the multiple tags. The default tag is latest.
How to run a Container and get Terminal Access?
First of all, Create a container using the ubuntu 14.04 image and connect to STDIN and a terminal.Execute the following command:
sudo docker run -i -t ubuntu:14.04 /bin/bash
Now, Create a user in your container using your first and last name as the username. Here is the command:
After adding the username, add the user to the sudo group and command to add is:
adduser username sudo
Now, exit from the container using the exit command.You will get the notice how the container shutdown.
Then again run the following command
sudo docker run -i -t ubuntu:14.04 /bin/bash
Now, try and find the user you have added.
A container only runs as long as the process from you specified docker run command is running.
Here I am ending the article. Docker is more suitable for your project depends on what you want to build in the end.If you have any question,let me know in comment section.