blue and red cargo ship on sea during daytime
Sat Jan 21

Why Should I Learn Docker?

It’s been a while now since I first learned about containers.This technology is somewhat catching my attention real quick as it is greatly helpful as a development infrastructure. So, what is a container? And of course, what is Docker? Let’s talk about it today.

What is a docker?

When we first create an application, we will usually need a production server to deploy the application. In order for the applications to run properly, many things need to be done on the production server, such as installing runtime, libraries, operating systems, web servers, databases.

By using Docker, all of this will be bundled into a single package known as container. By default, these containers will be isolated from each other. So in this case, the dependency installation mentioned above needs to be done for each container. In practice, this package bundling will make it much easier for us to deploy the applications we’ve made.

How does a container differ from a virtual machine?

See the diagram below.

VM vs
container.png

Although at first glance it seems like a virtual machine (click [here](https://www.binaryte.com/blog/everything-you-need-to-know-about- virtual-machine) to learn more) and container are quite similar, it is not. From the diagram above, we can see that a full-fledged OS means that the running OS includes all the components necessary to run software, such as the kernel, device drivers, system libraries, and user-space utilities.

Shared OS means the running OS will use the kernel from the host system. However, shared OS still loads the libraries and dependencies needed to run the application on its own. In this manner, both are still creating their own isolation environment, although the main differences between the two remain.

Deployment & isolation

To run a virtual machine, you will need a VM manager (Hypervisor) such as VMware, Virtualbox, or Hyper-V which is Windows exclusive. In this virtual machine, you can then install various operating systems.

Say that you are currently using Windows. You are using VMware and have installed several operating systems on it, such as Ubuntu for VM1 and Arch Linux for VM2. Thus, you have run multiple VM on a hypervisor (VMware) on a single physical machine.

On the contrary, containers will use what we call a container manager for orchestration such as Kubernetes or the most popular now is Docker. Bundling packages and applications made that have been described previously, will run on top of the host OS.

Let’s say you are using Ubuntu as the host OS. With Docker, you can run applications and package bundles using other OS, such as Debian, CentOS, or Alpine Linux. Unlike the OS that runs on a VM, this OS runs on a container in minimum conditions, where this OS is still able to run the applications and the dependency that we need normally.

However, each container will remain isolated from other containers. Docker also makes it possible for multiple containers to connect one to another under pre pre-defined network managed by the container manager. However, it is also important to know that it also makes VMs to have a higher degree of isolation as compared to containers.

Resource usage & scalability

Still related to the previous point, VM uses resources specifically dedicated to it such as CPU, memory and storage. This of course will burden the work of the running OS, especially the VM running with type 2 hypervisor.

Contrary to this, containers require much fewer resources since they share the resources with the host OS despite being a dedicated resource. Despite using its own kernel, containers rely only on the kernel of the host. As a result, containers are lighter and overall, leading to better scalability than VM.

Why do you need to learn Docker?

This is where things get more interesting. If you ask anyone with an IT background, you may have a lot of reasons to learn it. Personally, I really love it as we can make something like Docker Labs.

Let’s take an example of how you can take advantage of Docker containers. Say that you want to start blogging and you don’t want to be hassled with the nitty gritty of code everything by yourself from scratch. You can use Wordpress for this exact reason.

Wordpress is the most popular blogging tool. If you check on its official website, you can find that it requires PHP and SQL databases like MySQL or MariaDB. With Docker, you can have everything all in one in a single container without you having to install any of these things.

Another thing you take into consideration is by using the container, you can run softwares in the background all the time. This is very useful if you are interested in creating your own homelab, or just want to run apps on the home server.

There are many, so many applications that are already available on Docker Hub. I found some of them are really interesting to have on your server, such as Pihole for blocking internet tracker, Wireshark for analyzing packets, or Nginx for web hosting

Regarding Docker, I am blown away by the features KASM workspaces offer. The amazing thing about its service is that you can run an entire OS right out of your container. I don’t mean to exaggerate, but yes you can have the Kali Linux streamed onto the web browser. It also makes the data not persistent by default which is greatly helpful in terms of privacy and anonymity. Do I mention that you could run it on Raspberry Pi?

KASM workspaces also have the Trace Labs which are based on the Kali Linux specifically used for reconnaissance purposes. Unfortunately, I’ve tried it myself and somehow can’t have it running on Raspberry Pi. I am not affiliated with KASM workspaces, but the technology it brought with the container has changed my perspective on Docker containers.

Conclusion

Docker really does a great job in packaging the application along with its dependency into a single container. Isolation and the ability to run across different environments makes it extremely versatile. The lightweight and performant behavior gives the real edge over virtual machines. That being said, whether you are a developer or an avid hobbyist, learning how to use Docker can be very beneficial.