Fundamentals of Docker

Fundamentals of Docker

Intro

In this article, We’ll explore what docker is, why it is used, the difference between containerization and virtualization, a simple Workflow that uses it, docker architecture, and when it should be used and when it should not be used.

What is docker?

Docker helps developers build, share, run, and verify applications anywhere — without tedious environment configuration or management. In simple words, docker packages code and dependencies into a single lightweight unit that is portable across different environments which solves the problem of misconfiguration.

Why is docker used?

The application that the developers built had to be configured manually according to the dependency requirement which can be a library version, OS version, or package with a specific requirement. This meant, the application to work across different environments, every environment had to be tediously configured or managed. If not the classic problem, "It works on my machine" arises. To solve this problem, containerization came into existence. Docker is one such containerization solution that enables developers to build, deploy, and manage applications consistently and efficiently.

Containerization vs Virtualization

Before the dawn of containers, Virtual Machines were the only option for isolation. The application with multiple servicesThe with different dependencies required multiple VMs, each running a full OS with the associated overhead. Scaling the application would involve more complexity and resource consumption, as each VM needs to be provisioned, booted, and managed separately.

After using containers, the application is split into multiple microservices, each running in its own Docker container. This setup allows the development team to update, test, and deploy each microservice independently. The entire application can be scaled by adding more container instances as needed, ensuring high availability and performance.

If you see the above Picture, the Infrastructure which is the physical server needs a hypervisor to install many VMs and each VM needs a separate guest OS and binary/library dependencies that the different apps require. All these required a lot of resources, space, and cost.

In turn, containers provide a resource-efficient solution, They only need one OS that runs a container engine like docker, then on top of it runs a lightweight docker container that packages code and dependencies into a single unit.

Simple workflow using docker

When the application is developed, It's promoted to higher environments and finally, it's used by the user in the production environment. Docker makes this process easier by assuring consistency across different environments as discussed above. Let's see what happens exactly.

The Dockerfile contains the instructions to build a Docker image. Dockerfile says what is the OS required, what are the dependencies and packages to be installed, the port the application runs on, and several other instructions to build an image.

Docker image contains the dependencies and code packaged as a single unit. Docker image is pushed to a container registry such as Dockerhub, ECR, or Artifactory which are container repositories that contain images.

Docker containers are the running instances of docker images that can be pulled from the container registry such as dockerhub, these containers can be pulled to different environments and they run the same, ensuring consistency across the different environments. This avoids misconfiguration and management issues.

Docker Architecture

  1. Build an Image:

    The user runs docker build using the Docker client, which sends the build request to the Docker daemon. The daemon reads the Dockerfile from source code, assembles the image, and stores it locally on the Docker host. The docker client can be a CLI interface or a docker desktop GUI installed in the local system.

  2. Push an Image to the Registry:

    The user runs docker push to upload the image to a registry. The client sends this request to the daemon, which then pushes the image to the specified registry.

  3. Pull an Image from the Registry:

    The user runs docker pull to download an image from a registry. The client requests the daemon to pull the image, which the daemon retrieves and stores locally.

  4. Run a Container:

    The user runs docker run via the Docker client. The client tells the daemon to create and start a container from a specified image. The daemon pulls the image if not available locally, then creates and starts the container on the Docker host.

These components work together to provide a seamless and efficient containerization platform, enabling consistent application deployment and management.

Conclusion

This article is the summary of the video https://www.youtube.com/watch?v=ul96dslvVwY. Thanks to Piyush Sachdeva for creating the CKA series and docker fundamentals video.

Additional Resources

This article scratches the surface of docker and provides a basic high-level overview about docker. You can explore further by following the resources:

https://roadmap.sh/docker

https://docs.docker.com/guides/docker-overview/

https://youtu.be/RqTEHSBrYFw?si=fS07xb5ALSCRJ4xd