Containers - What are they and why use them?
When I started working in the IT sector, I spent much of my time building public-facing websites. In the early days, I used HTML, CSS and JavaScript and hosted them on web servers such as Microsoft's Internet Information Server (IIS). As time moved on, these websites became more complex and interactive and as my skills expanded, I moved to developing desktop applications.
A recent change in role (a move to the UK Hydrographic Office as Senior Developer) has brought me back into the world of web applications and, with this in mind, I am taking the opportunity to look more closely at some newer technologies and thought that I would bring you along for the ride!
So containers: what are they and why use them?
What are containers?
Straight away I should be clear that we are talking about containers in the context of software development and not those observed on the back of a lorry, freight train or cargo ship!
Traditional containers are used for keeping things in an organised, manageable and easily transportable package. In this context, I am referring to keeping software applications better organised, more manageable, as well as giving them greater portability across various platforms.
Containers are often confused with virtual machines (VMs) and while there are similarities, the underlying technology relies upon virtualisation. Containers and virtual machines do different things and solve different problems.
A VM provides a complete operating system which can be used like any other physical computer. You can log onto it, install applications, and do work on it. The difference between a VM and a physical computer is that the VM is run on a hypervisor and not installed onto the physical hardware. The hypervisor is a thin software layer that provides separation between the operating system and the hardware. This provides the advantage that a VM can be moved from one piece of physical hardware to another. Multiple VMs can be run on the same physical hardware allowing better resource management across an infrastructure.
In contrast, a container is generally lightweight and only includes the code necessary to support the application that it is running. You don’t log on to a container, although you can access and use the applications that it supports. A container is separated from the physical hardware by both the underlying operating system and the container engine. Like a VM, a container has separation from supporting infrastructure and can easily be moved between different physical hardware. Multiple containers can also be supported by the same infrastructure.
Why would I use a container?
A container offers a lightweight, highly portable and manageable solution for supporting or hosting modern software applications.
Multiple containers can be managed by the container engine and multiple containers can be orchestrated to work together, support each other, and build a redundant and resilient software infrastructure.
As containers are lightweight and can run on different platforms, it is easy to move this infrastructure as required. This provides an excellent platform for managing a variety of development environments — which is a key requirement for many software engineers.
Once configured, a container environment can be started and stopped quickly.
Containers solve the age-old issue of “it works on my machine”. By configuring a software application to run within a container, you have confidence that the application will run on any container engine upon which it is deployed. The user does not have to install the application, they simply download the image and run the container.
When you remove a container from your environment, you simply turn it off and delete its image. There is no underlying connection with your environment and therefore nothing to uninstall.
Conclusion
Containers are a technology that offers great potential to the modern software engineer, particularly in the creation and management of development environments. A thorough understanding of this technology is advantageous so that the opportunities that containers present can be fully considered and utilised.
Would you like to know more about containers? Consider reading my post “An introduction to Docker on Windows”.