Docker For Beginners

Harshit SahuHarshit Sahu
4 min read

In the world of DevOps and modern software development, efficient resource management and fast deployment are crucial. Virtual Machines (VMs) were once the standard go-to for isolating environments, but they come with overhead in terms of resources and boot-up time. Enter Docker, a containerization technology that has revolutionized how we package, deploy, and run applications. Docker allows developers to say "bye " to the resource-heavy VMs and embrace lightweight containers for better scalability, portability, and efficiency.

Docker vs Virtual Machine (VM) – Key Differences You Should Know

Why Docker is Different from Virtual Machines

Virtual machines require a complete guest operating system, consuming substantial memory and CPU. Each VM includes a full-blown OS, which leads to longer boot times and resource duplication. Docker, on the other hand, uses containers that share the host's OS kernel. This means containers are far more lightweight, launching within seconds with significantly reduced overhead.

Containers allow applications to be bundled with their dependencies into one single package that runs anywhere, whether it's on your laptop, a server, or in the cloud. This is achieved with isolated environments, similar to VMs, but with fewer resources needed.

All images

Docker’s Architecture

Docker containers run on top of the Docker Engine, which consists of three main components:

  1. Docker Client – the interface through which users interact with Docker.

  2. Docker Daemon – runs in the background and manages Docker containers.

  3. Docker Registry – stores container images, with Docker Hub being the default public registry.

In contrast to a VM's need for a hypervisor to manage multiple OS instances, Docker Engine sits directly on the host OS, allowing you to run multiple containers using shared system resources.

Docker Engine Architecture: A Beginner's Shallow Dive

Efficiency of Docker: Faster Boot and Less Resource Usage

Virtual Machines take minutes to boot because they initialize a whole operating system every time they start. With Docker, you are just starting a containerized application, which can take seconds since it shares the host operating system kernel. This allows rapid scaling and faster development cycles.

Moreover, Docker uses less disk space than VMs. A typical container image is just tens of megabytes in size, compared to several gigabytes for a VM image. This results in reduced storage costs, especially when deploying numerous applications in a cloud environment.

Intro to Docker

Portability and Consistency Across Environments

One of Docker’s superpowers is portability. Since a Docker container packages all dependencies needed for your application, you can run the same container on your local machine, in testing, and in production without worrying about inconsistencies. This makes Docker perfect for Continuous Integration/Continuous Deployment (CI/CD) pipelines, where developers need to ensure their application works exactly the same across different environments.

This is also where Docker beats VMs. Moving a VM from one environment to another can be cumbersome and time-consuming. Docker containers, on the other hand, can easily be exported, shared, or moved, making them ideal for multi-cloud and hybrid-cloud strategies.

An overview on Infinispan and its operational modes – Technologies ...

Implementing Docker: A Simple Workflow

Getting started with Docker is straightforward. Here’s a simple example of how to get an application running inside a Docker container:

  1. Install Docker on your system.

    • On Linux, this can be done via apt-get install docker.

    • On Windows and Mac, Docker Desktop provides a user-friendly interface.

  2. Write a Dockerfile – A Dockerfile defines the steps to build your container. It specifies the base image, application dependencies, and runtime commands.

     # Use an official Python runtime as a parent image
     FROM python:3.8-slim-buster
    
     # Set the working directory
     WORKDIR /app
    
     # Copy the current directory contents into the container
     COPY . /app
    
     # Install any needed packages specified in requirements.txt
     RUN pip install --no-cache-dir -r requirements.txt
    
     # Run the application
     CMD ["python", "app.py"]
    
  3. Build and Run Your Container – Use the Docker CLI to build your container and start it.

     docker build -t my-python-app .
     docker run -d -p 5000:5000 my-python-app
    
  4. Access Your Application – Once the container is up and running, you can access it via the specified port.

Conclusion: The Future is Containers

Docker has dramatically changed the way we think about running applications. By providing a lightweight, portable, and efficient solution, Docker has made it easier for developers and operations teams to work together and deliver applications faster. The reduced overhead compared to VMs, along with consistent environments across the development lifecycle, make Docker the clear choice for modern DevOps workflows.

In a world where agility, scalability, and performance are critical, Docker is paving the way for containerization technology to replace traditional virtual machines. So, say goodbye to VMs and embrace Docker for a faster, more efficient future!

0
Subscribe to my newsletter

Read articles from Harshit Sahu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Harshit Sahu
Harshit Sahu

Enthusiastic about DevOps tools like Docker, Kubernetes, Maven, Nagios, Chef, and Ansible and currently learning and gaining experience by doing some hands-on projects on these tools. Also, started learning about AWS and GCP (Cloud Computing Platforms).