Docker is rapidly emerging as a technology of choice for packaging and deploying modern distributed applications. It has become synonymous with containers. But what exactly is Docker and why should you use it?
This article gives you an introduction to how Docker works. It explains the benefits the technology brings to enterprise IT. It takes you through the key Docker concepts and features. And it also explores how to get the best out of your Docker container environments.
But what exactly are containers anyway? So, before we discuss Docker, let's tackle the fundamentals of containers first.
What Are Containers?
Containers are an alternative to the traditional virtualization method of using virtual machines (VMs) for partitioning infrastructure resources.
Whereas VMs are fully fledged guest operating systems, containers are much more streamlined operating environments that provide only the resources an application actually needs.
This is down to the way containers are abstracted from the host infrastructure.
Instead of using a hypervisor to distribute hardware resources, containers share the kernel of the host operating system with other containers.
This can significantly lower the infrastructure footprint of your applications, as your containers can package up all the system components you need to run your code without the bloat of a full-blown operating system.
Their reduced size and simplicity also means they can stop and start more quickly than VMs. This makes them more responsive to fluctuating scaling requirements.
And, unlike a hypervisor, a container engine doesn't need to emulate an entire operating system. So containers generally offer better performance compared with traditional VM deployments.
Containers and the Cloud
Containers are ideally suited to the modern cloud approach to application architecture—where, instead of using one large monolithic program, you break it up into a suite of loosely coupled microservices.
This offers a number of benefits. For example, you can replicate microservices across a cluster of VMs to improve fault tolerance. That way, in the event of an individual VM failure, the application can fall back on other microservices in the cluster and continue to function.
What's more, microservices are easier to maintain, as you can patch or update the code and system environment of your containers without affecting the others in your cluster.
Containers and DevOps
The compact design of containers makes them highly portable. As a result, they're easy to incorporate into Continuous Integration (CI) and Continuous Delivery (CD) workflows using DevOps tools with the available CI/CD tools such as Jenkins and CodeShip .
They're also a highly practical tool for developers, as you can host them on different servers with different configurations, provided each server operating system uses the same Linux kernel—or one that’s compatible with the container environment. This allows coders to work collaboratively on projects regardless of the host environment each of them is using.
But, above all, containers make life easy for developers, because they can focus on their code without worrying about the underlying infrastructure on which it will eventually run.
Why Should I Use Docker?
Docker is one of a number of different container platforms. So why would you use it as opposed to any of the alternative solutions?
First, it's by far the most widely used container service and easier to deploy than other versions of the technology.
Secondly, it's open source. So it's a robust, secure, cost-effective and feature-rich solution, which is backed by a large community of companies and individuals contributing to the project. Moreover, you're not tied to a specific vendor.
In addition, as the leading container platform, it offers strong support and a large ecosystem of complementary products, service partners and third-party container images and integrations.
Finally, the platform also allows you to run Docker containers on Windows. This has been made possible by means of a Linux virtualization layer, which sits between the Windows operating system and the Docker runtime environment. As well as Linux container environments, Docker for Windows also supports native Windows containers.
Docker still leads the way in an evolving container landscape, where alternative technologies are now gradually maturing. Nevertheless, Docker still remains the best choice in the majority of use cases.
Key Docker Concepts
The following are the key concepts you'll need to understand before you get started with the Docker platform.
The application you install on your host machine to build, run and manage Docker containers. It is the core of the Docker system and brings all the other components of the platform together. In other words, it generally refers to the Docker implementation as a whole.
The component of the Docker engine that listens to and processes API requests to manage the various other aspects of your installation, such as images, containers and storage volumes. The Docker daemon is the workhorse of the Docker system.
The primary user interface for communicating with the Docker system. It accepts commands via the command-line interface (CLI) and sends them to the Docker daemon.
A read-only template used for creating Docker containers. It consists of a series of layers that package up all the necessary installations, dependencies, libraries, processes and application code for a fully operational container environment.
A living instance of a Docker image that runs an individual microservice or full application stack. When you launch a container you add a top writable layer, known as the container layer , to the underlying layers of the Docker image. This is used to store any changes made to the container throughout its runtime.
A cataloging system for hosting, pushing and pulling Docker images. You can use your own local registry or one of the many registry services hosted by third parties, including Red Hat Quay , Amazon ECR , Google Container Registry and Docker's own official image resource Docker Hub .
A Docker registry organizes images into storage locations known as repositories, where each repository contains different versions of a Docker image that share the same image name.
Now we understand the fundamentals of Docker, let's finish by briefly exploring other aspects of containers you'll need to consider.
Once you're ready to deploy your application to Docker, you'll need a way to provision, configure, scale and monitor your containers across your microservice architecture.
These are typically able to:
- Allocate compute resources between containers
- Add or remove containers in response to application workload
- Manage interaction between containers
- Monitor the health of containers
- Balance the load between microservices
Cost and Performance Optimization
Finally, you'll need to optimize your deployments to ensure you get the best performance and efficiency from your containers.
Start by streamlining your containers as much as possible by packaging only what your application needs. This also helps to minimize their attack surface and improve their security .
And make sure you monitor your containers, maintaining a good balance of CPU and memory allocation, cluster sizing and replication of microservices so they make efficient use of resources.
These steps are particularly important in cloud-based deployments, because unnecessary resource consumption adds additional and unnecessary costs to your monthly cloud bills.
Learn More about Docker