Containers, Docker explained..

Containers, Docker explained..

What is a container? and why is it different than a virtual machine?

In the cloud world you will see a lot of people trying to squeeze many virtual machines into a physical server. The smaller the VMs the better, because it means more cost savings. The problem was that VMs are really big. They contain a full copy of the operating system, web server software, database software and the application run-time that will host your application plus your application. To grasp it, if your app is about 100 MBs, the run-time, web server and the operating system may take about 10s of GBs. And that’s only disk space. What about memory, processor, network resources …etc.

The other workaround, was to put many applications inside one virtual machine, and hope they don’t conflict with each other. If one of them needs an OS update, new run-time version or any other requirement, you cross your fingers, not to produce conflicts with the other apps on the same machine. This would create chaos, because you can’t be sure what will go wrong with every deployment.

Then comes the containers, a way to share common resources between “logical” virtual machines while still keeping every app isolated from the others. Think of it like, if 2 VMs are using the same operating system, then they can share the common files of the operating system while still have different versions of other files that got updated by system update, or different configurations. This way the bulk of files are shared and different parts are separate. Same thing for the web server, the app run-time and the other resources. Each container will have a separate network IP, ports, so both apps can do whatever they like with total isolation. How does containers work internally is not our subject, but think of it as a VM with the size of 100–200 MBs instead of 30 GBs. This would make you run 20 containers on your laptop instead of 1 or 2 virtual machines.

What is Docker and Docker Hub?

Docker is the company that revolutionized the containers idea, developed the containerd standard and created Docker (software) that build/run these container images. You start with a Dockerfile, a text file that describes how to build a docker image, what operating system/run-times to use, what ports and configurations are needed, …. Then Build a container image from this file. You can then use docker to run this image locally or store it in a registry so that others can download it and use it.

Docker Hub is a public registry, a place where every company/open source team can publish their container images. On Docker Hub you will find all OS companies have published multiple flavors of their OSes. You will find run-time images for .NET/Java/PHP… with every combinations of OS. You will find images for all types of databases, and images that has pre-configured software.

Who should make use of containers?

For Developers, docker means you can write software in any language with just a text editor and then build and run it inside a container that comes with OS/run-time/SDKs that are preconfigured for this language. Without the need to install or configure anything on the development PC. It also mean that after building and testing this image locally. You can be sure that this same image is the one that is going to run in production, same OS/run-time and same configurations. No need to provide deployment scripts or documentation, you just provide the container image to the IT engineers. Which effectively makes the container “A standardized unit of software”.

For IT Operations, it provides cost savings for being able to run many more apps on the same servers. It streamline deployment, not having to worry about internal application configurations and OS versions. Isolated and hassle free environment between different apps. And flexibility in dealing with small containers that can be moved around between physical servers easily for being too small.