Learnitweb

Introduction to Docker

1. Introduction

In this tutorial, we’ll discuss Docker and few terms related to it. We’ll also see how to get started with Docker.

2. Before Docker

Let’s discuss things before Docker.

Whenever the business required a new application, the IT department would purchase a new server. Often, the performance needs of the application were unclear, leaving the IT team to make educated guesses about the appropriate model and size of the server to acquire. Then came the virtual machine (VM) by VMWare, Inc. This allowed us to run multiple business applications safely on a single server.

The major problem with VM is that every VM requires its own dedicated operating system (OS). Every OS consumes CPU, RAM and other resources that could be used elsewhere. There are other problems with VM like they are slow to boot, managing VM workloads between hypervisors and cloud platforms is harder and OS patching and monitoring. There is licensing cost involved with the OS as well.

3. Containers

The container is roughly analogous to the VM. A key distinction is that containers don’t need a complete operating system of their own. In fact, all containers on a single host share the host’s operating system. This approach significantly conserves system resources like CPU, RAM, and storage. It also lowers potential licensing expenses and minimizes the workload associated with OS patching and other maintenance tasks. The overall impact: savings in time, resources, and capital. Containers are quick to start and highly portable. This makes it easy to move containerized workloads seamlessly from your laptop to the cloud, and then to virtual machines or bare metal servers in your data center.

4. Docker and Windows

Windows desktop and server platforms support both of the following:

  • Windows containers
  • Linux containers

Windows containers run Windows apps that require a host system with a Windows kernel. Windows 10, Windows 11, and all modern versions of Windows Server natively support Windows containers. Any Windows host running the WSL 2 (Windows Subsystem for Linux) can also run Linux containers. This makes Windows 10 and 11 excellent platforms for developing and testing both Windows and Linux containers. Despite Microsoft’s efforts in developing Windows containers, most containers in use today are Linux containers. This is mainly because Linux containers are smaller, faster, and have more extensive tooling and support available.

It’s important to note that containers share the host’s kernel. As a result, Windows containers require a host with a Windows kernel, and Linux containers need a host with a Linux kernel. However, it’s not always that straightforward. As mentioned earlier, Linux containers can be run on Windows machines using the WSL 2 backend.

Note: There are no Mac containers. However, you can run Linux containers on your Mac using Docker desktop. This works by running your containers inside a lightweight Linux virtual machine on your Mac, providing a seamless experience.

5. Kubernetes

Kubernetes, often abbreviated as K8s, is an open-source container orchestration platform designed by Google to automate the deployment, scaling, and management of containerized applications. Kubernetes is the most popular tool for deploying and managing containerized apps.

6. Docker

When we say Docker, we are referring two things:

  • Docker, Inc. the company
  • Docker the technology

6.1 Docker, Inc. the company

Docker, Inc. is a technology company based out of San Francisco founded by French born American developer and entrepreneur Solomon Hykes.

The company started out as a platform as a service (PaaS) provider called dotCloud. Behind the scenes, the dotCloud platform utilized Linux containers as its foundation. To facilitate the creation and management of these containers, they developed an internal tool that they ultimately referred to as “Docker.” This is how Docker technology came into existence!
The name “Docker” was chosen to evoke the concept of shipping and logistics. Just as dock workers manage the loading and unloading of cargo, Docker technology manages the packaging, distribution, and deployment of applications within containers. The metaphor highlights the ease with which developers can “ship” their applications across different environments, ensuring consistency and efficiency in deployment. The name captures the essence of containerization, where applications and their dependencies can be moved and executed seamlessly, much like shipping goods from one location to another.

In 2013, they phased out the underperforming PaaS segment of the business and rebranded the company as “Docker, Inc.”

6.2 Docker, the technology

Docker is a software that runs on both Windows and Linux. Docker can create, manage and even orchestrate containers. Docker is based on the ‘Moby’ open-source project initiated by Docker Inc.
The Docker as technology is mainly three things:

  1. the runtime: The runtime operates at the lowest level and is responsible for starting and stopping containers (this includes building all of the OS constructs such as namespaces and cgroups). Docker uses a tiered runtime architecture that integrates high-level and low-level runtimes working in tandem. This layered approach allows Docker to efficiently manage container lifecycle tasks, such as creation, execution, and management, with each runtime handling specific aspects of the process.

    The low-level runtime used by Docker is called runc, which serves as the reference implementation of the Open Containers Initiative (OCI) runtime specification. Its primary role is to interact with the host operating system to start and stop containers. Each container on a Docker node is created and managed by an instance of runc, making it a critical component in the container lifecycle management within Docker.
    The higher-level runtime is called containerd, which oversees the entire container lifecycle, including tasks like pulling images, managing container states, and orchestrating runc instances. Pronounced “container-dee,” ‘containerd’ is a graduated project of the Cloud Native Computing Foundation (CNCF) and is widely used by both Docker and Kubernetes for container management. In a typical Docker installation, there is a single long-running containerd process that instructs runc to start and stop containers. Unlike containerd, runc is not a persistent process; it runs only momentarily to initialize a container and then exits once the container is up and running.
  2. the daemon (also know as the engine): The Docker daemon (dockerd) operates above containerd and handles higher-level functions, including exposing the Docker API, managing images, volumes, networks, and other related tasks. Dockerd acts as the main service that users interact with, orchestrating and coordinating container operations through containerd. One of the key roles of the Docker daemon (dockerd) is to offer an easy-to-use, standardized interface that abstracts the complexities of the underlying container runtimes. This allows users to manage containers, images, networks, and other resources without needing to interact directly with the lower-level components.
  3. the orchestrator: Docker includes native support for managing clusters of nodes running Docker, known as swarms, using a technology called Docker Swarm. Docker Swarm is user-friendly and widely adopted in real-world production environments due to its simplicity and ease of installation compared to Kubernetes. However, it lacks many of the advanced features and extensive ecosystem that Kubernetes offers, making it a lighter but less feature-rich alternative for container orchestration.

The following figure shows the three layer Docker architecture:

7. The Open Container Initiative (OCI)

The Open Containers Initiative (OCI) is a governance body dedicated to standardizing the fundamental, low-level components of container infrastructure. Its primary focus is on defining standards for container image formats and runtime specifications, ensuring compatibility and interoperability across different container tools and platforms.

From the beginning, Docker’s popularity skyrocketed, leading to widespread adoption and, inevitably, some frustrations. A notable conflict arose when CoreOS (later acquired by Red Hat and then by IBM) disagreed with Docker’s approach and created an alternative standard called appc, along with its implementation, rkt (“rocket”). This led to competing standards within the container ecosystem, causing confusion and slowing adoption. To resolve this, industry leaders formed the Open Containers Initiative (OCI), a governance body under the Linux Foundation, to standardize container infrastructure. The OCI has since published specifications, including the image-spec and runtime-spec, which have significantly influenced the architecture of modern Docker and Docker Hub.

8. Docker Desktop

Docker Desktop is a desktop application developed by Docker, Inc. that simplifies working with containers. It comes with the Docker engine, an intuitive user interface, and an extension system featuring a marketplace. These extensions provide valuable functionality, such as scanning images for vulnerabilities and simplifying image and disk space management.

Docker Desktop is free for educational use, but a paid subscription is required for professional use.

Upon installation, Docker Desktop provides a fully functional Docker environment ideal for development, testing, and learning. It includes Docker Compose and allows you to enable a single-node Kubernetes cluster if you wish to explore Kubernetes. On Windows, Docker Desktop supports both native Windows containers and Linux containers, while on macOS and Linux, it supports only Linux containers.

9. Docker on Windows

Docker Desktop on Windows requires all of the following:

  • 64-bit version of Windows 10/11
  • Hardware virtualization support must be enabled in your system’s BIOS
  • WSL 2

Docker Desktop can be downloaded from Docker official website. The installation is straightforward.

Once it is installed, up and running you can verify using ‘docker version’ to verify. The output should be similar to this for you:

C:\>docker version

Client:
 Cloud integration: v1.0.35-desktop+001
 Version:           24.0.5
 API version:       1.43
 Go version:        go1.20.6
 Git commit:        ced0996
 Built:             Fri Jul 21 20:36:24 2023
 OS/Arch:           windows/amd64
 Context:           default

Server: Docker Desktop 4.22.1 (118664)
 Engine:
  Version:          24.0.5
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.6
  Git commit:       a61e2b4
  Built:            Fri Jul 21 20:35:45 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

10. Switch to Windows Containers

The output shows OS/Arch: linux/amd64 for the Server component, indicating that the default installation is configured to work with Linux containers. This is the standard assumption in most setups. To switch to the Windows containers – Right click on the whale icon in the system tray > Switch to Windows containers…

Note that any existing Linux containers will continue to run in the background, but you won’t be able to view or manage them until you switch back to Linux container mode.

11. Other ways to try Docker

The two other popular ways to try Docker are:

  • Installing Docker with Multipass
  • Play with Docker – https://labs.play-with-docker.com/

12. Conclusion

Docker simplifies application development, deployment, and management by providing consistent, isolated environments through containers. In this introduction, you learned about key concepts like images, containers, Dockerfiles, and Docker Hub, and how Docker enhances workflows across development and production.

As you continue exploring Docker, you’ll discover more tools that can streamline your processes. Embrace Docker to boost efficiency, ensure consistency, and elevate your development skills. Happy Dockering!