Today we are going to talk about containers and docker.
But … what is Docker?
It is very likely that lately in one way or another you have heard about Docker in some context: in a conference, a developer of your company, someone of systems, when talking about environments, deployments …
And is that this technology is quite related to the area of systems, with the environments in which software applications are executed.
The idea behind Docker is to create lightweight and portable containers for software applications that can run on any machine with Docker installed, regardless of the operating system(Linux, Unix, etc.) that the machine has below, thus facilitating the deployments.
This concept is already old, and comes from Linux (“chroot” or “jail” ), but to make a simile with the real world, imagine in your head a container of those that usually carry merchandise ships, which contains different products or a pendrive.
It is something self-contained, that can be carried from one place to another independently, it is portable. Now, going back to the software, so that we can access an application as normal users, that software application needs to be running on a machine, on a computer. But also, depending on the type of application, this computer also needs to have installed a series of things for the application to run correctly: a certain version of Java installed, an application server (eg tomcat, which is the software that will actually be running my application and making it possible to interact with it). Docker, allows me to put in a container (“a box”,) all those things that my application needs to be executed (java, binaries, etc) and the application itself. So I can take that container to any machine that has Docker installed and run the application without having to do anything else, or worry about what software versions that machine has installed, if it has the necessary elements for my application to work.
Which the benefit of using docker?
Maximizes hardware usage
Docker relies on the native tools of Linux Kernel to isolate and secure the container, in this way you can run several containers within the same machine without performance penalties because they use the same hardware without hypervisors or need extra resources.
As we have already mentioned, Docker generates fully autonomous containers and thanks to its system to build them, we can share our container with anyone by passing only the code that has been used to generate it. In this way we avoid moving hundreds of megabytes through the Internet.
The containers are completely isolated from the host machine or from any part of the ecosystem outside the container. This feature makes Docker a very safe tool and allows us, among other things, to limit our applications without fear of breaking anything else.
Since the intervention of additional hardware and / or hypervisors is not necessary, the deployment and startup time of a container is reduced to a few seconds compared to a start of a virtual machine, which takes several minutes.
What is the main difference between using a virtualization software such as VirtualBox and using a Docker container?
The main difference between both technologies is that, on the one hand, when we virtualize an operating system with VirtualBox we install and execute 100% of the operating system, with its kernel, its environment, its libraries, its dependencies, etc. Just as we install Windows or Linux on a real computer, it is installed completely in VirtualBox.
When we use Docker containers, for example, things change. Instead of virtualizing a complete operating system, we only create a small kernel with the libraries and dependencies necessary to perform our task, ignoring everything else. In this way, containers are not a virtual operating system as such, but rather are understood as “packages” that run isolated on the main operating system, but without relying on a virtual system.
When should I use Docker or VirtualBox?
If you want to use a complete operating system above our main one, then the best we can do is turn to VirtualBox. In this way we will have the complete system and we can use it as we use our main system, but with the security that if something happens (for example, we are infected by a virus), the main system is not affected.
On the contrary, if what we need is a specific application, or several instances of a server (for example, several Apache web servers), instead of having to install several virtual operating systems and run them completely in memory, the best option It is Docker, executing what is strictly necessary to meet our needs, without wasting resources and, in addition, in a much faster and simpler way.