Categories
Tech

What The Heck Is Docker? Is It Good For Me?

Many people talk about Docker these days. But most of them are hard to understand because people made it sounds too complicated. Today, I want to explain what Docker is in a simple way. Then I’m going to expand into why we should use it, and what are the use cases.

Docker in One Sentence

Docker is a technology that lets you quarantine an application in a tiny version of a Linux virtual machine and runs your applications.

Why You Should Use Docker?

Code Runs The Same in All Environments

Remember the last time when your code works at your local machine but doesn’t work when it’s deployed to the server? By using Docker, this kind of moment will become history. You can put all your applications with the dependency configured in one package(a.k.a. a Docker image). No matter what environment you’re running your application, all the dependents will be created exactly the same. There will be no more “it works at my local but doesn’t work on the server” moments. Isn’t it awesome?

Docker is Really Fast

Imagine you need to setup a virtual machine, how long does it really take? An hour? Thirty minutes? Docker can do that within seconds. Yeah, you heard me rights. Not minutes, but seconds!

For example, if you want to create a Debian Buster environment. Your only need to run two commands. One to download the Debian Docker image to your machine. This part only needs to be done once. Next, run that image with Docker. Just within a few seconds, you can have a fully functional Debian system running. Check out the following video.

Here’s an example of me running an instance of the Debian container from Ubuntu

Did you see how fast it is?

Code Quarantines

That’s right. Your code is quarantined inside a Docker container(I will explain what is a Docker image below). That means you can run an application using Node.js 14.2.0, a different application on 12.12.0, and another one on (if you really want)8.17.0, all in the same machine! The best part is, they won’t affect each other.

Potentially Saves Money

Back in the day, when we need different environments we need to create a new physical server and set up the OS. Now you can install multiple virtual machines with different OS in them. Docker is similar to a virtual machine. But with fewer overheads. Because Docker containers share the same resources, such as the Linux kernel. In the example of running multiple applications with different dependent versions of a framework, you don’t need to buy another virtual machine. Instead, you can put everything in the same virtual machine and run your application via Docker. If you have 10 virtual machines running 10 different environments, you can now do all of that in one machine. Of course, if your applications need to process a lot of data you’ll still need a different machine. But you got the idea.

So, what is Docker really?

Difference between virtual machines and Docker

Just like most computer applications, Docker runs on top of an operating system. We called this “Docker application” Docker. It mediates between the operating system and the tiny version of operating systems that runs on it. The difference between a virtual machine and Docker is that a virtual machine emulates the infrastructure of a computer. For example, CPU, memory, hard disk, etc. When we install an operating system on a virtual machine, it emulates the whole thing.

On the other hand, Docker runs on the Linux operating system. It shares what’s already running on the operating system and shares the resources with the tiny operating systems (Docker containers) that are run on top of it. For example, if your operating system is Ubuntu and you want to run a Debian container. Docker will share the kernel between Ubuntu and the Debian container. Therefore, instead of installing and running the full Debian operating system, you only need a minimal bit of Debian on top of Docker. It doesn’t need to emulate the infrastructure and spin up the whole operating system again. That’s why one of the reasons Docker is so fast.

Docker Image

Now we know that Docker can run a tiny version of a Linux operating system. How does Docker know what should be in each tiny operating system? That is a Docker image. If we just want to run a tiny version of Ubuntu, we’ll still need an image of Ubuntu. That’s a Docker image.

But that’s just the basics. The best part is, you can copy files from the outside to the image and build a new image. You can even host an application and expose specific ports of the tiny Linux. Sounds familiar? Yes, it works just like any virtual machine (but without a graphics interface) and takes much fewer resources from the host operating system.

Docker Container

A Docker container is nothing but a running instance of a Docker image. You can define what goes into a Docker image. For example, an operating system, dependency packages, your application, and so on. Once you run your Docker image, Docker will create an instance of your Docker image as a Docker container.

I have a post about How to Run Docker on Your old Raspberry Pi. That will give you some ideas of how Docker works in action.

If my note helped, please consider buying me a coffee😁.

Cheers,
Lok

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.