Why it is so popular and when to use it?

Docker Logo

What is Docker?

If you have been working as a software developer you may face some situations like your application works on your development machine, but doesn’t somewhere else.

For that, there can be some reasons.

  • If one or more files missing when deployment.
  • Software version mismatch.
  • Different configuration settings.

And this is where Docker comes to rescue.

With Docker, we can easily package our application with everything it needs and run it anywhere on any machine with Docker.

Docker Architecture

Docker Architecture

The Docker client

The Docker daemon

Docker registries

  • When you use the docker pull or docker run commands, the required images are pulled from your configured registry. When you use the docker push command, your image is pushed to your configured registry.

Who is Docker for?

DevOps

Docker is a tool that is designed to benefit both developers and system administrators, making it a part of many DevOps (developers + operations) toolchains. For developers, it means that they can focus on writing code without worrying about the system that it will ultimately be running on. It also allows them to get a head start by using one of the thousands of programs already designed to run in a Docker container as a part of their application. For operations staff, Docker gives flexibility and potentially reduces the number of systems needed because of its small footprint and lower overhead.

Docker Objects

Containers

As we discussed earlier, with Docker we can package our entire application with all of its needs such as libraries, configs, files, etc. and we can easily run these packages in a different environment inside Docker.

This isolation environment for running an application is called as Containers. We can run multiple applications in isolation.

Containers are very lightweight because containers don’t need a fully completed Operating System. In fact, all containers in a single machine shared the OS of the host.(Windows, Linux, etc)

Dockerfile

Docker Image

Example of a simple image for a Node.js application:

Once you have your Dockerfile written, you invoke the Docker build utility to create an image based on that Dockerfile. Whereas the Dockerfile is the set of instructions that tells build how to make the image, a Docker image is a portable file containing the specifications for which software components the container will run and how.

Because a Dockerfile will probably include instructions about grabbing some software packages from online repositories, you should take care to explicitly specify the proper versions, or else your Dockerfile might produce inconsistent images depending on when it’s invoked. But once an image is created, it’s static.

A Docker image typically contains,

  • A cut-down OS
  • A runtime environment (Eg: Node)
  • Application Files
  • Third-Party Libraries
  • Environment Variables and so on.

Containers vs Virtual Machines

Containers vs VMs

Virtual Machine (VM)

Problems with Virtual Machine

  • Slow to start, because the entire OS has to be loaded just like starting your computer.
  • Resource intensive, because each VM takes a slice of actual physical hardware resources. Like CPU, Memory, and disk space, etc.

Container

But containers are lightweight since it don’t use the separate OS for each and every container like VMs, instead, all containers in a single machine shared the Kernel of the Operating System of the host. So that means we need to license, patch, and monitor a single OS.

Also because the OS is already started in the host, a container can start up pretty quickly. Usually in a second.

Containers don’t need a slice of the hardware resources on the host. So we don’t need them to give a specific number of CPU cores, a slice of memory or disk space.

So in a single host, we can run ten, or even hundreds of containers side by side

So these are the differences between containers and virtual machines.

Docker Installation on Windows

  • Note: A 64-bit processor and 4GB system RAM are the hardware prerequisites required to successfully run Docker on Windows 10.

2. Then, double-click on the Docker Desktop Installer.exe to run the installer.

  • Note: Suppose the installer (Docker Desktop Installer.exe) is not downloaded; you can get it from Docker Hub and run it whenever required.

3. Once you start the installation process, always enable Hyper-V Windows Feature on the Configuration page.

4. Then, follow the installation process to allow the installer and wait till the process is done.

5. After completion of the installation process, click Close and restart.

Development Workflow

Devlopment workflow

So to start off let’s take an application (no matter what kind of it is or how it’s built) we take that application and dockerize it, which means we make a small change so that it can be run by docker. But how?

By simply adding the Dockerfile to the application. Dockerfile is a plain text file that includes the instructions that docker uses to package this application into an Image. This image typically containing all the things we need to run the application.

These images are downloaded from a Container Registry, a repository for storing images of containers. The most common of them is the Docker Hub.

Once we have the image we tell docker to start the container using that image.

When you run docker build . on the same directory as the Dockerfile, Docker daemon will start building the image and packaging it so you can use it. Then you can run docker run <image-name> to start a new container.

So then our application will get loaded inside that container and this is how we run our application run locally on our development machine.

So that's it for now. Hope you all got an idea about Docker and let’s put this knowledge into practice in the upcoming lessons.

Thank you very much.

A Computer Science enthusiast. Software Engineer. Full Stack developer. Music Lover