What is Docker in Easiest Manner ?
Are you sick of always missing a dependency that doesn’t allow you to run the app and therefore you have to debug it for hours trying to find what’s wrong? Are you sick of always uploading/hosting application to Netlify directly, Then you’ve come to the right place. In this article, you will learn how to make use of Docker to develop and ship your software faster and easier.
Step 1: Why do we even need it ?
Problem in Traditional Method
For me, the easiest way to understand a technology is to know the problem it solves. So why should we care? Why do we need Docker? Aren’t we doing well with our application? (Productivity app). It is fully operational, we have deployed it, and it is accessible over the internet. I don’t see any issues here — what do you think?
Your developer friend now wants to add more features to it. So he/she clones your GitHub repository and attempts to install it locally on his machine. Assume you are using Windows and your friend is using Linux; your machine has the 16th version of Node and your friend, for some reason, is using an older version of Node. Your project is fully compatible with your system and is operational. It could work on your friend’s computer or not. Unfortunately, it did not work due to an outdated node version. Your friend is unaware of this and spends a significant amount of time attempting to find out what went wrong. He calls and says your project isn’t working, yet it is at your end. Finally, you two fought and realized what went wrong. But you can’t get that lost time back.
The Solution
Fortunately, there is a simple solution to this issue. What if I told you that you could give your computer to that friend without actually handing it to them? You can send your friend a magic file with configurations that worked on your system. Then, using a tool, your friend can unlock the power of this magical file and successfully run your project on his PC.
This tool is called Docker, and the magic file is called Dockerfile, which we will discuss later in this article.
Virtualization Vs Containerization
Virtualization involves creating a virtual version of a physical machine, including the operating system, on top of a host operating system. This allows multiple virtual machines to run on the same physical hardware, each with its operating system and resources. Examples of virtualization software include VMware and VirtualBox.
Containerization, on the other hand, involves packaging an application and its dependencies together in a container. Containers are lightweight and fast, and they share the host operating system kernel, making them more efficient than virtual machines. Example of containerization software — Docker.
But because virtual machines utilize a lot of resources and often time consumes developers started using Docker.
Docker..
Docker is a containerization solution that allows you to package your entire software and run it from anywhere. In a file called Dockerfile, developers define project dependencies, instructions, and other variables. We can create an image and then a container using that Dockerfile.
Three main components of Docker
Docker Image: A Docker image is a sealed package that contains the source code files for your project. It is immutable, which means that once built, the files in that image cannot be altered. You must rebuild the image to update files. These images are created using instructions written in Dockerfile, which we will learn more about later in this tutorial.
Containers: Images are read-only which means you can’t run them. To run applications, we use containers. Containers are runnable instances of images.
Volumes: We have two problems here,
To begin with, data saved in containers will be lost once they are stopped. But, there may be times when we need data to persist and be shared between containers. Secondly, we are aware that docker images are read-only. However, in development, we frequently edit files. Every time we make a modification, we must rebuild the image. This will significantly reduce developer productivity and is a time-consuming process. We can use volumes to overcome these problems. Docker volumes are a way to store data outside of a container’s filesystem. They allow data to persist even if the container is deleted, and can also be used to share data between multiple containers.
Some Important Terms
A few terms you need to need to know before we start using Docker.
Docker Engine/Daemon
Docker daemon is similar to your brain (not exactly like a brain). It handles API requests as well as the management of Docker containers, images, volumes, and networks.
Docker hub
Docker Hub is a public registry where docker images can be found. While creating images, you can push them to Docker Hub so that others can use them.
Docker CLI
Docker CLI is a tool that may be used to create/delete images, run/stop/kill containers, create/delete volumes, pull images from the Docker registry, and much more.
Subscribe to my newsletter
Read articles from Vikrant Raut directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by