Aryan Shaily

Docker Containers and Microservices

July 29, 2024

My exploration of containers, their key elements, and their usage in Microservices.

Introduction

While reading about Microservices architecture, I dug into the differences between VMs (Virtual Machines) and containers, and found containers particularly interesting. Let’s take a closer look at what containers are, how they differ from VMs, and why they’re so popular—especially in Microservices setups.


What Is a Container?

A container is a controlled environment within a host machine. It communicates directly with the host’s kernel but operates in an isolated space, meaning that any actions performed inside the container won’t affect the host machine.

For example, if you’re using Docker, each container communicates with the Docker engine, which in turn sends messages to the host kernel. Containers allow you to do almost anything you’d do with a regular VM—like installing packages, running services, and so on—but with far less overhead.

When you create a new Docker container, all the components (file system, system programs, etc.) are copied from the base image. Essentially, you have instant access to everything that’s been packaged into the image.


Docker Simplifies It All

Technically, you can create a container by manually managing namespaces and cgroups. However, tools like Docker abstract away those complexities, making container creation and management straightforward.


Key Elements of a Container

1. Namespaces

2. Cgroups (Control Groups)


Containers vs. VMs


Containers in Microservices

Microservices are small, isolated services that communicate with each other to form a larger application. Because these services are typically focused on one task and require fewer resources, using a full VM to run each service would be overkill.


Final Thoughts

That’s a quick overview of containers—what they are, how they work, and why they’re so widely used in Microservices. If you spot any errors or have follow-up questions, feel free to let me know!


Tags:
#containers #docker #microservices


Useful Resources