Containers in Sitecore development- Part 1

 

What are containers?

Containers are executable units of software that code is packaged in, along with libraries and dependencies, so that it can be run anywhere, whether on a developer’s workstation, an on-prem server, or in the cloud, and deployed easily and consistently, regardless of the target environment.


Now, to understand the same in the Containers world, Containers contain everything needed to run the application (actual working images of the application and all the required libraries or any executable for development), so you need not rely on what is currently installed on the host. As per the above example, one Sitecore application requires an SQL server, .net code, Solr, etc. Containers will create images for all these dependent software and you need not worry about installing them on the client machines.

The key benefits of containerization include the following:

  • Lightweight – small size on disk and very low overhead.
  • Isolation – containers keep applications isolated not only from each other but also from the underlying system. Inherent constraints mean containers are secure by default.
  • Portability – a container runs on any machine that supports the runtime environment of the container. You can build locally, then easily move to on-premise or cloud environments. You can easily share containers while you work.
  • Loose coupling – containers are highly self-sufficient and encapsulated, so you can replace or upgrade one container without disrupting other containers.
  • Scalability – because containers are lightweight and loosely coupled, you can scale quickly by creating new containers.

What is Docker?

Docker is a software platform for building applications based on containers—small and lightweight execution environments that make shared use of the operating system kernel but otherwise run in isolation from one another. While containers have been used in Linux and Unix systems for some time, Docker, an open-source project launched in 2013, helped popularize the technology by making it easier than ever for developers to package their software to “build once and run anywhere.”

Docker was originally built for Linux, but it now runs on Windows and MacOS as well.

We usually use Docker and Containers interchangeably but in actuality both are different. Docker is software to containerize an application. There are many software available to containerize applications eg. Docker, Portainer, LXC, and Azure Kubernetes.

In Sitecore, the container technology for development is always Docker. For cloud deployment, we will use Azure Kubernetes Service (AKS).


Why Dockers?

“But it was running on my machine!”. Every developer has said this in his/her life while shipping his/her app to a friend or an app tester. To overcome this scenario, the Concept of containers or dockers arrived so that everyone on the team has the same application running on their machine regardless of any customization, server settings, or other customization that may be present on the target server.


Virtualization: Virtualization relies on software to simulate hardware functionality and create a virtual computer system. This enables IT organizations to run more than one virtual system – and multiple operating systems and applications – on a single server.

Difference between Virtual Machines and Containers: From a certain point of view a container is not so much different from a virtual machine. But, instead of creating a full operating system, a Docker Container has just the minimum set of operating system software needed for the application to run and relies on the host Linux Kernel itself. This allows a huge boost in performance (compared to a virtualized system you can save up to 8% processing power) and a reduced memory and disk footprint for your application. This means that containers are far more lightweight: they share the kernel, start faster, and use only a fraction of the memory compared to booting an entire operating system:

In a nutshell, Benefits of Dockers:

  • Docker enables more efficient use of system resources means cost savings on hardware and software licenses because you need many fewer operating system instances to run the same workloads.
  • Docker enables faster software delivery cycles
  • Docker enables application portability: Because Docker containers encapsulate everything an application needs to run (and only those things), they allow applications to be shuttled easily between environments. Any host with the Docker runtime installed—be it a developer’s laptop or a public cloud instance—can run a Docker container.
  • Faster onboarding for new developers or new team members on the project.
  • Less documentation.

Docker Terminology:

Dockerfile: Definition of an image. It is a way to create your custom docker images. It is a file or a script that contains a set of instructions to build an image. Usually, the first line specifies the base image followed by steps of copying the Dependency list, installing dependencies, copying source Code, and a startup command. Take the Ready to eat example, so consider the instructions written on the sachet as DockerFile.

Docker Image: Binary, containing the packaged version of your app. Template of the application. So as per our analogy, inside the ready-to-eat sachet, there are different ingredients that are compressed which can be considered images. A Docker image is a single file that comprises all the dependencies, Configurations files, and source code that are required to run an application. It is sort of a read-only snapshot or template which is used by containers to run applications. Docker image also consists of a very specific startup command that is useful when a Container start. For a Typical Sitecore XP application, there will be a CM image, CD image, Solr Image, SQL server image, Redis image, Traefic image, etc.

Container: Self-contained running application, running instance of an image. Docker image can’t run an application as it’s only a read-only file. Therefore, to run the application inside a docker image we need a run time environment that is called a container. Containers are lightweight and contain everything needed to run the application, so you do not need to rely on what is currently installed on the host. As per our analogy, Ready to eat sachet is a container.

Docker Hub: “App store” for docker images. It is the place where you can store the collection of different versions of a specific image. Versioning in docker images is usually enabled using tags. Docker Hub is a very larger docker registry where you can create repositories and store images with different versions.

Note that, Only Docker images can be shared and stored in Docker Hub. Containers are running versions of images that can be fired up on the client machines by using docker-machine on a need basis.

So, You have now understood, what are containers and dockers. What are the benefits of using containers? What is the basic terminology in containers and dockers? In the next blog, I will guide you are the Prerequisites to install a Sitecore application using Docker and the complete process.

Comments