Containers 101: Containerization
What are containers ?
Containers are completely isolated environments. They can have their own processes or services, their own networking interfaces, their own mounts just like virtual machines. Except they all share the same operating system kernel.
Why do you need containers?
Scenario: You have a project that requires you to set up an end to end stack including various different technologies like web servers using node js and a database such as mongoDB and an orchestration tool like ansible. Based on the mentioned technologies above you will have a lot of issues developing this application with all these different components:
- Their compatibility with the underlying operating system. You have to ensure that all these different services are compatible with the version of the operating system you plan to use. There are scenarios when certain versions of these services are not compatible with the OS(operating system)
- Setting up of new environments for users(Dev/Test/Prod environments) which takes long hours of setup as you have to make sure they are using the right operating system, the right versions of each of these and each developer has to set all that up by him/herself each time.
- The compatibility between the services and the libraries and dependencies on the OS(operating system). You may encounter issues where one service requires one version of a dependent library whereas another service requires another version. The architecture of your application will at some point change as time goes by and you will have to upgrade to newer versions of these components or even the database etc. Every time something changes you will have to go through the same process of checking compatibility between the various components and the underlying infrastructure.
This compatibility matrix issue is usually referred to as The Matrix from Hell (is the common word to describe setting up the development stack required to build an end-to-end application)
What do containers do?
Based on above scenarios/issues, you will need something that could help you with the compatibility issue (Eradicate the theory: it works on my end/machine but does not work on another end/host/machine). Something that will allow you to modify or change these components without affecting the other components and even modify the underlying operating system as required.
Are you looking/searching for this solution?! Well Docker has got you covered. With docker you will be able to run each component in a separate container with its own libraries and its own dependencies all on the same instance/virtual machine and the OS but within separate environments or containers.
Understanding Docker
To understand how docker works, case example would be the basic concepts of operating systems.If you look at Os like Suse, FEdora, centOS or Ubuntu, they all consist of two things: An OS kernel and a set of software.The Operating system kernel is responsible for interacting with the underlying hardware while the OS kernel remains the same which is Linux in this case, it’s the software above it that makes these OS different. THe software may consist of a different user interface, drivers, compilers, file managers or developer tools etc. So you have a common Linux kernel shared across all operating systems and some custom software that differentiates Os from each other.
Docker containers share the underlying kernel, what does sharing the kernel mean? Say you have an operating system with Ubuntu OS with Docker installed on it. Docker can run any flavor of OS on top of it as long as they are all based on the same kernel, in this case Linux. If the underlying operating system is Ubuntu, docker can run a container based on another distribution like Debian, Fedora Suse or centOS.
That’s the OS that does not share the same kernel as these above mentioned? Windows. You won’t be able to run a Windows based container on a docker host with Linux OS on it.
How is containerization done?
As of today, there are a lot of containerized versions of applications readily available. Most organizations have their products containerized and available in a public docker registry called docker hub or docker store already.
You can find images of common operating systems, databases and other services and tools. Once you identify the images you need and you install docker on your host. Bringing up an application stack is as easy as running a docker run command with the name of the image. For example when you run command docker run mongodb you create a mongodb instance.
Container vs Image
An image is a package or template just like a VM template that you might have worked with in the virtualization world. It is used to create one or more containers. Containers are running instances of images that are isolated and have their own environments and set of processes.