Containerization with Docker

Containers are a powerful tool for isolating, packaging and shipping applications.

What are containers?

To understand what containers are, it is important to first understand virtualization & virtual machines (VMs). VMs enable multiple operating systems in a single set of hardware which provides benefits such as:

  • Effective resource allocation

If two VM’s share the same hardware, each VM can take advantage of any under-utilized resources in the hardware.

  • Application isolation

Applications running on different VMs do not have access to each other’s data.

Containers takes the idea of virtualization further, while VMs virtualize the hardware, containers virtualize the operating system. The unit of isolation is a container image and is smaller than a VM image.

A container is a self-contained unit of software that contains everything required to execute the software. Containers are portable and resource-efficient. Multiple containers can run on the same operating system while still running as separate isolated processes. Container images are hosted in container engines, eg. Docker.

A container image will behave the same on any container engine and will enable you to build applications locally and deploy the same container image to a test or production environment.

Docker

Containerization in the context of Docker is considered as a runtime instance of a Docker image that contains the following:

  • A Docker image
  • An execution environment
  • A standard set of instructions

Core elements of the Docker ecosystem

The differences between a VM and a container

Virtual Machine (VM)Container
Hosts one or more applicationsHosts the application and it’s dependencies
Contains the necessary binaries and librariesShares the OS kernel with other containers
Exposes the guest OS to interact with the applicationsNot coupled to infrastructure and only requires the Docker Engine to be installed on the host
Executes isolated processes in the user’s workspace on the host OS

Benefits for developers

  1. Applications are portable and packaged in a standard way which makes deployment easier and repeatable.
  2. Tests, packaging and integration can be automated in a consistent application lifecycle.
  3. Supports microservice architectures.
  4. Alleviates platform compatibility issues.
  5. Simplifies release management with reliable deployments that improves the speed and frequency of releases.
  6. Enables consistency between between development, testing and production environments.
  7. Supports scalability for workloads on-demand for different use cases.
  8. Any issues or bugs can be isolated for debugging at a container level.
  9. Supports continuous integration in a deployment pipeline.

Docker build process

Dockerfile

A Dockerfile is composed from a base image, you can find a repository of base images on Docker Hub which already contains the latest updates and security configurations. A Dockerfile contains a set of instructions for building the Docker image.

//Example of a Dockerfile that will execute on Ubuntu

FROM ubuntu
CMD echo "Hello Naiomi!"

Build a Dockerfile into an image

Build the Dockerfile into a Docker image within your preferred IDE or run the following command

docker image build [OPTIONS] PATH | URL | -

Run the Docker image

docker run {image-name}

View all Docker images

docker images

Leave a Reply

Your email address will not be published. Required fields are marked *