Skip to main content

Docker Simplified - A Beginner's Guide to Containerization

· 4 min read

Introduction

Docker is a popular tool used by developers and IT professionals to streamline the process of building, packaging, and deploying applications. It allows applications and their dependencies to be packaged into lightweight, portable, and self-sufficient containers that can be run consistently across different environments.

What are Containers?

Containers are lightweight and portable packages that contain everything needed to run a software application, including the code, libraries, and settings. Containers are similar to virtual machines but are more lightweight and efficient, as they don't require a separate operating system. They are widely used in modern software development and deployment practices to package, distribute, and run applications in a consistent and reproducible way.

What is Docker?

Docker Docker is an open-source platform that allows you to package and run applications in containers, providing a lightweight, portable, and isolated way to develop, deploy, and manage applications across different computing environments.

Docker Architecture:

Docker Architecture

Docker Client: It is the primary component to interact with the docker host.

Docker Host /Server: It contains the main program called Docker-Daemon which listens to all API calls from the docker client and manages the docker objects such as containers, images, volumes, and networks.

Docker Registry: A Docker registry is a centralized repository for storing and sharing Docker images. Docker Hub is the default public registry, which contains a large number of official and community-contributed Docker images.

Docker Concepts:

Docker Image: A Docker image is a read-only template that contains everything needed to run a container, including the application, code, and configurations packed into a single file called Docker-Image. Docker images are stored in a registry, such as Docker Hub, from which they can be pulled to create containers.

Docker Container: Container is a running instance of a Docker Image. Containers are isolated from each other and from the host system, providing consistency and reproducibility across different environments.

Docker Compose: It is used to define applications by using multiple docker containers.

Docker Swarm: It is a collection of docker engines, if the service on the engine or node is down, that service can be run on another engine. It is a technique to create and maintain a cluster of docker engines. Service deployed on one node can be accessed on other nodes in the same cluster.

Docker Volumes: Volumes in docker is essentially a directory inside docker. It can be directly accessed by the container and it’s kept when you remove the container.

Difference between Bind Mount Volumes and Normal Volumes

Bind Mount VolumesNormal Volumes
Bind mount volumes are managed by UsersNormal volumes are completely managed by the docker
It is dependent on the directory structureIt’s not dependent on the directory structure
We need to take care of backup and migration and it’s not easy to take back-upIt is easy to take back-up and perform migration

What are Docker Networks?

Docker networks are virtual networks that allow containers to communicate with each other securely and efficiently. There are 3 types of networks:

Bridge Network: A bridge network is a private network that allows containers to communicate with each other on the same host or across hosts. Containers in a bridge network are connected to a virtual switch, which allows them to communicate securely and efficiently using container names or IP addresses.

Host Network: Here we create a container directly on the host network. Where the network configuration of a container should be the same as the network configuration of the host.

Null Network: It is used to create a container that doesn’t have any network interface. As there is no network interface, we can’t expose it externally and it is used to store data.

Basic Docker Commands

DescriptionCommand
Build the image out of the docker filedocker build –t image-name
Bring up the container from the docker filedocker run –d image-name
To get into a containerdocker exec –it container-id /bin/bash
To run the image into a containerdocker run –itd image-name
Check container statusdocker ps
To create imagedocker commit container-id new-image-name
To share the same data b/w multiple containersdocker volume –driver=nfs volume_name

In summary, Docker provides portability, consistency, efficiency, reproducibility, flexibility, scalability, DevOps integration, security, and a vibrant community, making it a powerful tool for modern application development and deployment.