Although many people want to compare Kubernetes and Docker, it's not actually an either/or question. This post looks at how the two powerful technologies can complement each other.
When it comes to container technologies, two names emerge as open source leaders: Kubernetes and Docker. A lot of people want to know which option is better, but that question is based upon a misconception. They are, in fact, fundamentally different technologies and don’t compete — it’s not an either/or question. And while they excel in their respective areas, they also are complementary and can be powerful when combined.
In this post, we’ll explore the fundamentals of Kubernetes and Docker and take a look at the advantages of using them individually and in tandem. To do so, it’s important to start with the foundational technology that ties them together: containers.
What is a container?
A container is an executable unit of software that packages application code with its dependencies, enabling it to run on any IT infrastructure. A container stands alone; it is abstracted away from the host operating system (OS) — usually Linux — which makes it portable across IT environments.
One way to understand the concept of a container is to compare it to a virtual machine (VM). Both are based on virtualization technologies, but while a container virtualizes an OS, a VM leverages a hypervisor — a lightweight software layer between the VM and a computer’s hardware — to virtualize physical hardware.
With traditional virtualization, each VM contains a full copy of a guest operating system (OS), a virtual copy of the hardware needed to run the OS, as well as an application and its associated libraries and dependencies. A container, on the other hand, includes only an application and its libraries and dependencies. The absence of a guest host significantly reduces the size of a container, making it lightweight, fast and portable.
For a full rundown on the differences between containers and VMs, see “Containers vs. VMs: What’s the difference?“
Engineers can use containers to quickly develop applications that run consistently across a large number of distributed systems and cross-platform environments. The portability of containers eliminates many of the conflicts that come from differences in tools and software between functional teams.
This makes them particularly well-suited for DevOps workflows, easing the way for developers and IT operations to work together across environments. Small and lightweight, containers are also ideal for microservices architectures, in which applications are made up of loosely coupled, smaller services. And containerization is often the first step in modernizing on-premises applications and integrating them with cloud services:
What is Docker?
Docker is an open source containerization platform. Basically, it’s a toolkit that makes it easier, safer and faster for developers to build, deploy and manage containers. Although it began as an open source project, Docker today also refers to Docker, Inc., the company that produces the commercial Docker product. Currently, it is the most popular tool for creating containers, whether developers use Windows, Linux or MacOS.
In fact, container technologies were available for decades prior to Docker’s release in 2013. In the early days, Linux Containers (or LXC) were the most prevalent of these. Docker was built on LXC, but Docker’s customized technology quickly overtook LXC to become the most popular containerization platform.
Among Docker’s key attributes is its portability. Docker containers can run across any desktop, data center or cloud environment. Only one process can run in each container, so an application is able to run continuously while one part of it is undergoing an update or being repaired.
Some of the tools and terminology commonly used with Docker include the following:
- Docker Engine: The runtime environment that allows developers to build and run containers.
- Dockerfile: A simple text file that defines everything needed to build a Docker container image, such as OS network specifications and file locations. It’s essentially a list of commands that Docker Engine will run in order to assemble the image.
- Docker Compose: A tool for defining and running multi-container applications. It creates a YAML file to specify which services are included in the application and can deploy and run containers with a single command via the Docker CLI.
Other Docker API features include the ability to automatically track and roll back container images, use existing containers as base images for building new containers and build containers based on application source code. Docker is backed by a vibrant developer community that shares thousands of containers across the internet via the Docker Hub.
But while Docker does well with smaller applications, large enterprise applications can involve a huge number of containers — sometimes hundreds or even thousands — which becomes overwhelming for IT teams tasked with managing them. That’s where container orchestration comes in. Docker has its own orchestration tool, Docker Swarm, but by far the most popular and robust option is Kubernetes. (See “Docker Swarm vs. Kubernetes: A Comparison” for a closer look at the Kubernetes vs. Docker Swarm debate.)
What is Kubernetes?
Kubernetes is an open source container orchestration platform for scheduling and automating the deployment, management and scaling of containerized applications. Containers operate in a multiple container architecture called a “cluster.” A Kubernetes cluster includes a container designated as a “master node” that schedules workloads for the rest of the containers — or “worker nodes” — in the cluster.
The master node determines where to host applications (or Docker containers), decides how to put them together and manages their orchestration. By grouping containers that make up an application into clusters, Kubernetes facilitates service discovery and enables management of high volumes of containers throughout their lifecycles.
Google introduced Kubernetes as an open source project in 2014. Now, it’s managed by an open source software foundation called the Cloud Native Computing Foundation. Designed for container orchestration in production environments, Kubernetes is popular due in part to its robust functionality, an active open source community with thousands of contributors and support and portability across leading public cloud providers (e.g., IBM Cloud, Google, Azure and AWS).
Key Kubernetes functions include the following:
- Deployment: Schedules and automates container deployment across multiple compute nodes, which can be VMs or bare-metal servers.
- Service discovery and load balancing: Exposes a container on the internet and employs load balancing when traffic spikes occur to maintain stability.
- Auto-scaling features: Automatically starts up new containers to handle heavy loads, whether based on CPU usage, memory thresholds or custom metrics.
- Self-healing capabilities: Restarts, replaces or reschedules containers when they fail or when nodes die, and kills containers that don’t respond to user-defined health checks.
- Automated rollouts and rollbacks: Rolls out application changes and monitors application health for any issues, rolling back changes if something goes wrong.
- Storage orchestration: Automatically mounts a persistent local or cloud storage system of choice as needed to reduce latency—and improve user experience.
For more information, see our video “Kubernetes Explained”:
Kubernetes and Docker: Finding your best container solution
Although Kubernetes and Docker are distinct technologies, they are highly complementary and make a powerful combination. Docker provides the containerization piece, enabling developers to easily package applications into small, isolated containers via the command line. Developers can then run those applications across their IT environment, without having to worry about compatibility issues. If an application runs on a single node during testing, it will run anywhere.
When demand surges, Kubernetes provides orchestration of Docker containers, scheduling and automatically deploying them across IT environments to ensure high availability. In addition to running containers, Kubernetes provides the benefits of load balancing, self-healing and automated rollouts and rollbacks. Plus, it has a graphical user interface for ease of use.
For companies that anticipate scaling their infrastructure in the future, it might make sense to use Kubernetes from the very start. And for those already using Docker, Kubernetes makes use of existing containers and workloads while taking on the complex issues involved in moving to scale. For more information, watch “Kubernetes vs. Docker: It’s Not an Either/Or Question”:
Integration to better automate and manage applications
Later versions of Docker have built-in integration with Kubernetes. This feature enables development teams to more effectively automate and manage all the containerized applications that Docker helped them build.
In the end, it’s a question of what combination of tools your team needs to accomplish its business goals. Check out how to get started with these Kubernetes tutorials and explore the IBM Cloud Kubernetes Service to learn more.
Earn a badge through free browser-based Kubernetes tutorials with IBM CloudLabs.