DEV Community

Cover image for Docker: An Introduction
Jenn Herrarte
Jenn Herrarte

Posted on

Docker: An Introduction

Earlier this month, I had the chance to attend DockerCon in Los Angeles. You can read more about that here...However, attending DockerCon inspired me to share an introduction to Docker!

First, let's try to come up with a mental model for what exactly Docker is. Imagine Docker as a standardized shipping container in the world of transport.

Back in the day...

In the real world of logistics and transportation, goods need to be transported from one place to another efficiently and securely. Traditionally, cargo was loaded and unloaded individually onto various types of vehicles, each with its own specific requirements and limitations. This process was time-consuming, error-prone, and costly.

old shipping boat

Now, consider Docker as the equivalent of a standardized shipping container. Just like a shipping container, Docker containers are designed to be a consistent, self-contained unit that holds everything needed for a particular "cargo" or application. Docker containers provide consistency, isolation, portability, efficiency, and scalability.

shipping containers

This is especially helpful as applications become more complex, with some having separate frontends, backends, and numerous dependencies.

Here are a few problems Docker can help solve:

Dependency Hell

  • Inconsistent Environments
    In the world of software development, an application typically goes through multiple stages, from development to testing and then deployment. The challenge here is that each of these environments can be slightly different in terms of configurations, libraries, and dependencies.

    This inconsistency often leads to the notorious "it works on my machine" problem, where an application behaves differently in different environments. Docker ensures consistency by packaging the application and all its dependencies into a single container. This container behaves the same way across different environments, eradicating the issue of inconsistent environments.

  • Dependency Hell
    Application development often requires specific versions of libraries, packages, and software dependencies. Managing these dependencies manually can be a nightmare, especially when multiple projects with conflicting requirements are in progress.

    Docker simplifies this by encapsulating an application and all its dependencies in a container. You define the required dependencies in a Dockerfile, and Docker takes care of the rest. No more worrying about dependency conflicts or complex installation procedures.

  • Isolation and Security
    Running multiple applications on a single server can be risky. If one application encounters a security vulnerability or a runtime issue, it can potentially affect other applications running on the same server.

    Docker offers containerization, which means each application runs in an isolated environment. A security breach or an application crash within one container won't jeopardize others, enhancing overall system security and stability.

  • Portability
    In a world where applications can be deployed on various platforms, from local development machines to cloud servers and everything in between, ensuring your application works consistently across these platforms can be challenging.

    Docker solves this problem by making containers portable. You can develop an application on your local machine, package it as a Docker container, and be confident that it will work the same way when deployed in the cloud or on-premises.

  • Resource Efficiency
    In traditional virtualization, each virtual machine requires its own operating system, which consumes a significant amount of resources.

    Docker containers share the host operating system's kernel, making them incredibly lightweight and efficient. This results in reduced overhead, better resource utilization, and the ability to run more containers on the same hardware.

Docker's Architecture

Docker's architecture is designed around a client-server model, which includes:

Docker Architecture

  • Docker Client
    The Docker client, also known as the Docker CLI, is the primary interface for users to interact with Docker. Users issue commands to the Docker client, which in turn communicates with the Docker daemon to carry out requested operations. These commands can be used to build, run, and manage containers, as well as interact with images and registries.

  • Docker Daemon
    The Docker daemon, or simply Docker, is a background service that manages container lifecycles. It listens for Docker API requests, processes these requests, and interacts with the host operating system to create and run containers.

    The daemon is responsible for building and managing containers based on Docker images. It ensures that containers run in isolated environments and communicates with the kernel of the host operating system to control resource allocation.

  • Docker Images
    Images are at the core of Docker's architecture. An image is a read-only template that includes a set of instructions for creating a container. Images are composed of multiple layers, which are stacked to form the final image. The layered approach enables images to be lightweight and efficient. Images can be created manually using Dockerfiles or pulled from registries.

  • Containers
    Containers are the runtime instances of Docker images. When you run a container, it's created from an image, and a writable container layer is added on top. This container layer allows the application to make changes without affecting the underlying image. Containers are isolated, lightweight, and ephemeral, making them perfect for running applications and services.

  • Docker Registry
    A Docker registry is a repository that stores and distributes Docker images. Docker Hub is the most well-known public registry, but organizations can set up private registries to store their images securely. Images can be pushed to and pulled from registries, making it easy to share and collaborate on software projects.

How Docker's Architecture Works

With this architectural foundation in mind, let's dive into how Docker operates:

  • Building an Image: You create an image by defining its configuration in a Dockerfile. This configuration includes specifying a base image, adding files, setting up environment variables, and executing commands. The Dockerfile is used to build the image.

  • Layered Filesystem: Images are composed of multiple layers. Each instruction in the Dockerfile creates a new layer, and these layers are cached and can be reused to speed up image creation.

  • Running a Container: You run a container from an image using the docker run command. The Docker Engine leverages the image's filesystem and adds a writable container layer on top. This container layer allows your application to make changes without affecting the underlying image.

Docker Engine

  • Isolation: Containers provide process and filesystem isolation. Each container runs in its isolated environment, separate from the host and other containers. This isolation enhances security and prevents conflicts between applications.

  • Resource Control: Docker allows you to control the resources allocated to containers, such as CPU and memory. You can also limit network access, making it possible to run multiple containers on the same host without interference.

  • Interacting with Containers: The Docker CLI and Docker API provide interfaces to interact with containers. You can start, stop, and manage containers, and even execute commands inside running containers.

  • Cleanup and Portability: Containers can be stopped and removed when no longer needed. Images can be shared with others, pushed to registries, and pulled to different environments. This makes applications highly portable and easy to manage.

Docker's architecture, with its client-server model, layered filesystem, and containerization principles, plays a pivotal role in its success. Understanding this architecture is crucial for harnessing Docker's power and streamlining your software development workflow.

With Docker, you're equipped to create, package, and deploy applications more efficiently and reliably than ever before. Docker, with its architecture and containerization, offers a seamless and reliable way to streamline the development and deployment of applications.

Top comments (5)

Collapse
 
davdomin profile image
David Dominguez

Great introduction to Docker! It's amazing how Docker simplifies the complexities of managing dependencies, ensures consistency, and enhances resource efficiency. The architecture breakdown is insightful, making it easier to grasp how Docker works. Thanks for sharing this informative piece!

Collapse
 
jennherrarte profile image
Jenn Herrarte

I appreciate the feedback! @davdomin

Collapse
 
clerijr profile image
Clerivaldo Junior

Really nice intro! Wanna see more articles like this :D

Collapse
 
sonyarianto profile image
Sony AK

Great Docker introduction, it's a game changer on software provisioning mechanism, easy to use, easy to scale, easy to custom.

Collapse
 
jennherrarte profile image
Jenn Herrarte

thank you!