Docker is a very popular tool in this fast-growing IT world. Many large and small-scale organizations, as well as startups, are continuously using docker in the production environment in their projects.
It is a tool designed to ease the process of development, deployment, and running of applications by using containers. This blog is an introductory guide to docker and covers the following concepts-
Before using containerization concept in the applications, we were using virtual machines to isolate and organize applications and their dependencies into VMs. So, virtual machines run many multiple applications in the same physical hardware and this process is called Virtualization.
But we know that virtual machines are ponderous in size and as we need to run multiple VMs, it leads towards terrible performance. Also, it creates several other problems, such as portability, software updates, or continuous delivery. These drawbacks of Virtualization were later ruled out by the introduction of a new concept, called Containerization.
Docker is a tool or a set of platform-as-a-service (PaaS) products that use the concept of OS-level virtualization to deliver the software in packages called Containers. We create containers that contain the software and its resources or dependencies after that we dockerize our application and can use it anywhere like in Mac, Linux, or windows.
As you see in the above figure, all the application libraries run inside separate containers. This shows that each application is independent of the other and no application can interfere in the execution of other applications.
Talking about containers, let me tell you a thing about them. Containers have the host operating system instead of the guest operating system. So, it can share relevant libraries and resources whenever needed.
Containers are lightweight in comparison to VMs as they share OS kernel and starts up faster and use a fraction of sections to run. So, yes, we can say that this is a better approach than using Virtual Machines in more than one way.
Here are two key concepts of docker-
As shown in the above figure, a docker file is created and when we run the build command, it converts to an image and after running it, it finally converted into a container.
A Dockerfile is a text document that contains all the information required for running your software in a base container. It contains all the commands that an end-user can call in the command line to build the docker-image.
Steps to create a custom image –
Let us take an example of creating a Dockerfile as shown in the below image –
package-lock.jsonfiles from our image by using the
RUNcommand so that it runs the corresponding command like
install node modulesin the .3. directory of our image.
Copy . .command and that command add our source code into the image.
CMDcommand which tells docker that this command will be run whenever our image is run inside the container.
docker buildcommand inside the terminal window.
docker build --tag node-dockerwhere,
node-dockeris the image name.
Docker has several reasons that differentiate it from others and make it popular among the programming community. Firstly, it boosts up your software delivery cycles. It is easier to put new versions of software into production quickly and we can also roll back to a previous version if needed. Furthermore, it also solves the problem of application portability.
Hope you liked this blog and it helped you get the basic knowledge about Docker so that you can consider using it in your next project.