Containers And Docker (2023) General Overview

Containerization is an approach to software development in which an application or service, its dependencies, and its configuration are packed together as a container image.

We can test the containerized application as a unit and deploy it as a container image instance to the host operating system (OS).

Containers also isolate applications from each other on a shared OS. Containerized applications run on top of a container host that in turn runs on the OS (Linux it Windows).

Each container can run a whole web application or a service, another benefit we can drive from containerization is scalability.

Docker

Docker is an open-source centralized platform designed to create, deploy, and run the applications. Docker is also a company that promotes and evolves this technology working in collaboration with cloud, Linux, and windows vendors, including Microsoft.

Docker containers can run anywhere on-premises in the customer data center in an external service provider or in the cloud.

Docker image containers can also run natively on Linux and windows. Windows images can run only on a windows host and Linux images can run on Linux host where a host means a server or a VM.

Windows Server Containers

Windows Server containers provide application isolation through process and namespace isolation technology. A windows server container shares a kernel with the container host and with all containers running in the host.

Hyper-V Containers

Hyper-V containers expand on the isolation provided by windows server containers by running each container in a highly optimized virtual machine. In this configuration the kernel of the container host is not shared with the Hyper-V containers providing better isolation.

Docker Terminologies

Container Image

A container image is a static file with excitable code that can create a container on a computing system. A container image is immutable means it cannot be changed and can be deployed consistently in any environment.

It is a core component of containerized architecture. It includes everything a container needs to run the container engine such as Docker or CoreOS, system libraries, configuration settings, and specific workloads that should run on the container.

The image shares the operating system kernel of the host, so it doesn’t need to include a full operating system.

Docker File

Docker provides a simple human-readable configuration file that specifies what a docker image should contain. It’s like a batch script.

The first line states the base image, to begin with, and then follows the instructions to install required programs, and so on until we get the working environment that we need.

Build

The action of building a container image based on the information provided by its docker file, plus additional files in the folder where the image is built. We can
build images with this command: –> docker build

Container

A container is a runnable insurance of an image. It consists of a Docker image an execution environment and a standard set of instructions. We can create, start, stop, move, or delete a container using the Docker API or CLI.

We can connect a container to one or more networks and also we can attach storage to it or even create a new image based on its current state. Containers are relatively isolated from each other. When scaling the service we can create multiple instances from the same image.

Volumes

Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. It’s completely managed by Docker and it lives in the host system.

It offers a writable file system that the container can use because most programs need to write to the file system so volumes add a writable layer on top of the container image so the programs have access to a writable layer on top of the container.

Volumes have several advantages, easier to backup and migrate, we can manage volumes using Docker CLI and Docker API, it works on both Linux and Windows containers, Volumes drivers let us store volumes on remote hosts as well as on cloud providers to encrypt the contents of volumes, or to add other functionality.

Tag

Tag, is a mark or a label we can apply to docker images so that different images or versions of the same image (depending on the target environment) can be identified.

Multi Stage Build

Multi stage build is a feature that helps to reduce the size of the final images. With multi stage build we can multiple FROM statements in our Dockerfile.

Each of them instructions can use a different base, and each FROM begins a new stage of the build. We can copy the artifacts from one stage to another which we want in our
final image.

Repository

Repository allows us to share container images with the team, customer, or the Docker community at large. Docker images are pushed to the docker hub through the “docker push” command.

A single repository can store many docker images (stored as tags). Images are labeled with the tag that indicates the image version.

Registry

A registry is a storage and content delivery system, holding named docker images, available in different tagged versions.

It’s a highly scalable server-side application that stores and lets us distribute docker images. The registry is open source and we can find the source code on GitHub.

Multi-Arch Image

It’s the feature that simplifies the selection of the appropriate image according to the platform where docker is running it’s for multi-architecture. A multi-arch image reference multiple existing images that are compiled for different architectures.

When a container is started from a multi-arch image, Docker selects and uses the image that matches the architecture of the Docker host.

Docker Hub

Docker hub is a public registry (owned by Docker as an organization) to upload images and work with them. Docker hub provides Docker image hosting, public or private registries, build triggers, and webhooks, and we can integrate it with GitHub and Bitbucket.

Docker Trusted Registry

Docker trusted registry (DTR) is the enterprise-grade image storage from Docker. We install it behind our firewall so that we can securely store and manage the docker
images that we use in our applications.

Docker Desktop

Docker desktop is an application that we can install on our machines like Mac, Linux, and Windows. It enables us to build and share containerized applications and microservices.

It provides a GUI (Graphical User Interface) that lets us manage our containers, applications, and images directly from our machine.

Compose

Compose is a tool for defining and running multi-container Docker applications. It works in all environments production, staging, development, testing as well as CIworkflow.

With this, we can use a YAML file to configure our applications services. Then with a single command, we can create and start all the services from our
configuration.

Conclusion

Docker has revolutionized the way software is developed, deployed, and managed. Its containerization technology allows developers to create consistent environments that can be easily moved across different platforms, ensuring that applications work seamlessly across different systems.

Docker’s ability to simplify the deployment process and reduce infrastructure costs has made it a popular choice for many organizations. Its vibrant community and extensive documentation make it easy to get started and learn. With its many benefits, Docker has become an essential tool for modern software development and is expected to continue to play a critical role in the industry for years to come.

FAQ’s

Q: What Are Some Benefits of Using Containers?

Ans: A containers offer several benefits including,

Consistent Environment

Containers ensure that our application runs the same way on any system, regardless of the underlying infrastructure.

Lightweight

Containers are smaller and faster than virtual machines, which means we can run more of them on the same hardware.

Isolation

Containers isolate applications from each other and from the underlying system, which makes them more secure and reliable.

Portability

Containers can be easily moved from one environment to another, such as from development to production, or from one cloud provider to another.

Q: How Do We Create a Docker Container?

Ans: To create a Docker container, we need to define a Dockerfile, which is a text file (written in a YAML) that specifies the steps needed to build the container image. Once we have a Dockerfile, we can use the “docker build” command to build the container image, and then use the “docker run” command to start the container.

Q: How Do We Scale Our Containers?

Ans: Docker provides several options for scaling containers, including:

Manual Scaling

We can use the Docker CLI or dashboard to manually start and stop containers as per the requirement.

Docker Compose

We can define a set of containers in a Compose file and use the “docker-compose up” command to start and scale them together.

Docker Swarm

We can use Docker Swarm to create a cluster of Docker nodes and use the “docker service” command to deploy and scale container services across the cluster.

Kubernetes

We can use Kubernetes to manage and orchestrate containerized applications at scale, using features such as replication controllers, services, and deployments.

Q: How Do Containers Differ From Virtual Machines?

Ans: Virtual machines (VMs) is a complete computer system, including the hardware and operating system, while containers share the host operating system and kernel. This means that containers are much lighter and faster than VMs, and require less overhead to run.

Containers also offer more consistency across different environments, as they can run the same way on any system with the same kernel.

Q: How Do I Deploy Docker Containers To The Cloud?

Ans: There are several cloud platforms that support Docker containers, including Amazon Web Services (AWS), Microsoft Azure, Google Cloud Platform (GCP), and DigitalOcean. These platforms provide tools for deploying and managing containers at scale, and can integrate with Docker registries to automate the deployment process.

Leave a Comment