For that, let us look at the pictorial representation of three concepts and learn layer by layer.
From the picture above, it must be crystal clear that in case of:
- Virtualization: It runs on top of the host Operating System.
- Hypervisor: It runs on top of hardware, also known as bare-metal virtualization.
- Docker: It also runs on top of the host OS but there is a small difference.
Question: So, If docker also runs on the top of the host Operating System, how is it different from virtualization?
Answer: In case of virtualization, each machine created whether it is a Windows, or Linux or macOS, or any other operating system, will install its own kernel and hence,
Virtualization vs Docker
The picture above shows some key differences between virtualization and docker:
- Hardware = It rarely matters, 99% of the time, no difference at all.
- Host OS = Any OS can be used for both, but because of some reasons, Linux suits best for docker.
- Images = It can be seen, that the size of an image is very big in the case of virtualization as compared to the other.
- Storage = After the start, during the running state as well, the size of virtual machines is again big as compared to Docker containers.
- Boot Time = Again, the boot time of virtual machines is very high, whereas docker containers run very fast, in seconds.
Question: Why docker is best suited on Linux?
Answer: The reason behind this is that the docker’s main application/utility utilizes the OS’s kernel for its task/job completion.
Question: What is actual meaning of the answer given above?
Answer: It means that the containers created under the docker application are kernel-less and they use native Host OS’s kernel to perform tasks, that is why containers are efficient, fast, small, and portable.
Question: What are some different names of docker?
Answer: They are following:
- Container-Based Virtualization
- OS Level Virtualization
- Lightweight Virtualization
Virtual Machines vs Docker Containers
Virtual Machines = Guest OS + Binaries/Libraries + Application’s code
Docker Containers = Binaries/Libraries + Application’s code
There is a small yet big difference between containers and virtual machines and that is the Guest OS layer.
As discussed above, containers use Host OS’s kernel but virtual machines need their own native kernel in order to perform tasks.
Note: Docker containers run as the isolated user-space process under Host OS via sharing its kernel.
Note: Docker containers are nothing but applications/code packed with their dependencies.
Question: So, apart from all the above discussed, what is the main purpose behind using docker and its containers?
Answer: An application packed with its dependencies can be transported to the test environment, to the development environment, to the production environment without worrying about any kind of error.
Before Docker = An application’s code is written and compiled, when the application is tested and executed on developer’s computer/laptop and (dependencies are > mysql5 and php6), but when the same compiled code is sent to tester and tried to run “it eventually fails”, from here the problem begins.
Problem = Tester was unable to figure out the root cause of the error, so the developer is told to recheck the code, the code is rechecked and it is again running without errors on developer’s machine, but when resent to tester, the problem persists.
Root Cause = The root cause is nothing but dependency problem, i.e. the version of MySQL and PHP being used on the tester’s machine is different from that of the developer’s machine, mysql5 + php6 on the developer’s machine but on the tester’s machine, it is mysql3 + php4.
Comment = It may look like a small problem on this scale, but in a real-time production environment, it may result in drastic problems.
Solution = Docker Containers, it is the only way to remove such problem, because containers are packed applications with their dependencies.
- docker architecture
- What is an Operating System?
- What are different times related to a process?
- What is
Inter ProcessCommunication or IPC in OS?
- What is a Deadlock and its prevention techniques?