Containers in Sitecore development

Current version: 10.0

This topic gives a brief overview of containers, Docker, and how you can use Docker when you develop in Sitecore.

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.

Containerization of an application provides a clean separation of concerns, as developers focus on their application logic and dependencies, while deployment teams focus on deployment and management.

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.

  • 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 are loosely coupled, you can scale quickly by creating new containers.

Differences between containers and virtual machines

Instead of virtualizing the hardware stack, containers virtualize at the operating system level, with multiple containers running atop the operating system kernel directly. 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:

The difference between containers and virtual machines.

For a more in-depth comparison, see Containers vs. virtual machines.

What is Docker?

Containers first appeared several years ago, but modern container development accelerated with the introduction of Docker in 2013.

Docker is both an open source project for building applications on containers, and also a company that promotes and evolves the technology. They also own Docker Hub, which is the official registry of Docker. Docker has become synonymous with containers because it has been very successful at popularizing it. Docker was originally built for Linux, but it now runs on Windows and MacOS as well.

In Sitecore, the container technology is always Docker.

Terminology

Docker and containers use a specific terminology. These are some of the terms that are used:

  • Image - a package with all code and dependencies that serves as the blueprint for creating a container. An image is often based on another image, with some additional customization. An image is immutable once it has been created.

  • Dockerfile - a text document format that contains instructions for assembling a Docker image. This file is used by the Docker CLI build command to build the image.

  • Registry - a place where you store images. This can be either public (Docker Hub) or private (Azure Container Registry). A registry contains one or more repositories.

  • Repository - a collection of images with the same name, labeled with tags to indicate the version or variant. In an image reference, the repository is the part before the final colon, for example, mcr.microsoft.com/windows/servercore in mcr.microsoft.com/windows/servercore:ltsc2019.

  • Tag - a reference to a specific image within a repository. In an image reference, this is the part after the final colon, and it is often used for a version number or architecture variant, for example, ltsc2019in mcr.microsoft.com/windows/servercore:ltsc2019. If you do not specify a tag, Docker defaults to the tag name latest.

  • Container - an instance of an image. It consists of the contents of a Docker image, an execution environment, and a standard set of instructions.

  • Compose - a CLI tool and (YAML based) text document format created by Docker. You use it to define how multi-container applications run. After you create the definitions, you can deploy the entire multi-container application with a single command (docker-compose up). This command a container per image.

  • Orchestrator - a management tool for containers. It helps you deploy and manage containers in production. Kubernetes is the most used, and it is well supported by Microsoft through the Azure Kubernetes Service (AKS).

Container-based Sitecore development

There are a number of reasons why the use of containers is attractive for Sitecore development, and it becomes even more attractive as Sitecore moves towards a microservices-based architecture. Containers lend themselves very well to this architecture (and in fact encourage it).

Other reasons are:

  • No install - no installation using SIF (Sitecore Installation Framework), SIM (Sitecore Instance Manager), and so on. Sitecore provides container images ready to use. You can get an instance up and running with docker-compose up, and container images will download automatically.

  • Multi-project efficiencies - you can run multiple Sitecore instances simultaneously without worrying about things like conflicting versions of SQL and Solr. You can start and stop entire instances quickly when jumping between projects.

  • Simplified onboarding - the onboarding process is as simple as: install prerequisites, clone your code repository, run docker-compose up.

  • Environment consistency - eliminate issues due to environment inconsistencies. When you containerize your build, you have complete control of the build environment.

  • Environment stability - because containers are immutable, you do not have to worry about ruining your local Sitecore instance. Use docker-compose down and docker-compose up to get up and running again.

There are many benefits for Sitecore developers. However, for an organization, there are other considerations. To help you decide whether containers and Docker are right for your team, see this article on the Sitecore Knowledge Center.

Sitecore images

Starting with Sitecore version 10.0, container images for all roles and topologies are available at scr.sitecore.com, the Sitecore Container Registry (SCR).

For previous versions of Sitecore, you can use the docker-images community repository. This requires more work because you must first build the images, but the process is scripted and well documented. Refer to this knowledge base article for information about support for containers prior to version 10.0.

Sitecore Docker resources

The container documentation references and uses the following resources:

  • Docker Examples - Repository containing an example Visual Studio solution with recommended structure for container development, and Docker compose files for building Sitecore instances in various topologies.

  • Helix Examples - The same Sitecore Helix-focused example repository, updated for Sitecore 10 with Docker containers.

Do you have some feedback for us?

If you have suggestions for improving this article,