What is Kubernetes vs Docker Compose? Comparison of these DevOps tools


Kubernetes and Docker Compose are both container orchestration frameworks. Kubernetes runs containers on a number of computers, virtual or real. Docker Compose runs containers on a single host machine.

Let’s look at the details.

Docker is a technology used to build and run containers. A container is a collection of one or more processes, organized under a unique name and identifier that are isolated from other processes running in an IT environment. This computing environment can be a physical computer or a virtual machine. Unlike a virtual machine, a container has no life outside of an operating system. A virtual machine has its own operating system. This, it is quite possible to run a virtual machine with a Windows operating system on top of a host machine that is running Linux. Containers, on the other hand, take advantage of an existing host operating system.

A comparison between Kubernetes and Docker composes

Understanding Docker Compose

As mentioned above, Docker Compose is a container orchestration technology intended to run a number of containers on a single host machine. The developers create a Docker Compose file that describes the container images and configuration for composing Docker Compose. The default name for this file is docker-componse.yml. Listing 1 below shows an example docker-compose.yml file.

version: “3.9”
the Web:
to build: .
– “5000: 5000”
– my network
image: “redis: alpin”
– my network
my network:

Listing 1: A docker-compose file that publishes two services, web and redis

One of the cool features of Docker Compose is that it allows developers to expose a container as a service and organize those services under a “network”. This allows a number of containers to run on the host while being organized and isolated based on the network under which the given container is running.

As you can see from Listing 1 above, that docker-compose.yml declares a named network, my network on line 14. The docker-compose.yml file also declared two services, the Web, on line 3 and repeat on line 9. These services run under the network, my network as reported in lines 8 and 12, respectively. These two services are isolated under my_service. However, because the service, the Web exposes port 5000 on line 6, users can access the the Web service container through port 5000.

One of the additional features of Docker Compose is that it can create containers using container images hosted on a container repository such as DockerHub. Additionally, Docker Compose can create containers based on a Dockerfile stored on the hosting machine. Regarding List 1 above, note in line 10 that the service, repeat uses a container image, redis: alpine hosted on Docker Hub. However, the service, the Web builds its container from the local Dockerfile according to the to build attribute, as defined in line 4.

The important thing to understand about Docker Compose is that it allows you to run many containers on a single host as separate services and each service can be configured to run on one or more services on a Docker network. Compose particular. Kubernetes, on the other hand, is intended to run containers as a service on one or more machines, virtual or real.

As mentioned above, Kubernetes is a container orchestration technology. In Kubernetes, the logic of a web application is segmented into containers. The containers are organized into an abstraction called pod. A pod can have one or more containers. The logic of a pod is exposed to the network through another Kubernetes abstraction called service. In short, the network knows about Kubernetes services, and a service knows which pod (s) have its logic. Within each pod is one or more containers that do the logic in the given pod. (See Figure 2, below)

Docker Compose and Kubernetes clusters

A Kubernetes service exposes the logic of a pod’s container (s) to the network

In Kubernetes, containers, pods, and services are hosted in a collection of one or more computers, real or virtual. In Kubernetes parlance, a computer is called a node. Kubernetes runs on a number of nodes. The collection of nodes is called a Kubernetes cluster.

Pods and containers associated with a service can be hosted on multiple machines. Additionally, Kubernetes has scaling and fault tolerance features that allow Kubernetes to automatically create more pods at runtime to meet increased demand without loss of service. Additionally, if a pod fails, Kubernetes will automatically replenish it. Docker Compose supports automatic restarts on failure, but is not intended to support automatic scaling.

The important thing to understand about the difference between Docker Compose is that while in Docker Compose a container and its corresponding service and network run on a single machine, in Kubernetes containers are organized in an abstraction called pod. . A pod can be used by one or more services, and pods associated with a single service are typically spread across multiple machines.

Source link


Comments are closed.