Container Technology Overview and Installation

Container Technology Overview and Installation

Overview of Containers

Introduction to containers

Container technology is a lightweight virtualization method that allows multiple applications to run on a single host operating system. Containers provide an isolated and complete environment for applications to run without interfering with each other.

Containers contain all the dependencies and relevant libraries needed to run the application.

History of containers

Virtual machines were useful but are resource intensive as each VM needs its own OS to function. To counter this issue concept of containerization came into where the relevant software and all its dependencies are packed in a container that can be shared and deployed easily to any environment.

containers-vs-virtual-machines.jpg

Key features of container technology

  1. Isolation: Containers provide an isolated environment for applications to run. Each container has its own file system, network, and process space, which helps ensure that applications are isolated and secure.

  2. Lightweight: Containers are much lighter than virtual machines, as they share the same operating system kernel with the host machine. This makes them faster and more efficient, as they require fewer resources and as they are sharing the same operating system they can dynamically allocate resources between them.

  3. Portability: Container images can be easily moved between different environments, such as development, testing, and production. This allows developers to create and test applications locally and then deploy them to production without having to worry about compatibility issues.

  4. Scalability: Containers can be easily scaled up or down, depending on demand. This makes it easy to handle sudden spikes in traffic or usage, without having to provision additional hardware or resources.

  5. Flexibility: Containers can be easily customized and configured to suit different application requirements. Developers can create and manage container images, add new packages or libraries, and deploy applications without worrying about compatibility issues.

  6. Automation: Container technology can be easily integrated into automated deployment and testing pipelines. This makes it possible to automate the entire software development lifecycle, from building and testing to deployment and monitoring.

  7. Orchestration: Container orchestration tools, such as Kubernetes, provide a powerful and flexible platform for managing containers at scale. They allow developers to automate the deployment, scaling, and management of containerized applications while ensuring high availability and reliability.

Architecture of container technology

  • Container Engine: This is the core component of container technology that manages the lifecycle of containers. It is responsible for creating, starting, stopping, and deleting containers, as well as managing container networks and storage

  • Container Images: These are read-only templates used to create containers. They contain everything needed to run an application, including the application code, runtime, libraries, and dependencies

  • Container Registry: This is a repository that stores container images. It allows users to easily share and distribute container images across different environments

  • Container Orchestration: This is the process of managing and scaling containers across multiple hosts. It ensures that containers are deployed in the most efficient way possible and that they are highly available and resilient

  • Container Networking: This is the process of connecting containers to form a network. It allows containers to communicate with each other and with other services in the same network

Installation of Docker

Prerequisites

A Virtual Machine or an EC2 instance with the following packages

# Installing EPEL Release
sudo yum install <https://dl.fedoraproject.ortg/pub/epel/epel-release-latest-9.noarch.rpm> -y

# Installing Dependencies
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

# Adding docker repository
sudo yum-config-manager --add-repo <https://download.docker.com/linux/centos/docker-ce.repo>

Installation

Installing docker-ce

# Instaling docker stable version
sudo yum install docker-ce -y

There will be a prompt to accept gpg key, if the fingerprint matches with 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35 then press y

Starting docker services

# Starting Docker service
systemctl start docker

# Enabling Docker service
systemctl enable docker

Create an admin user for docker and add it to the docker group

# Creating docker user for administration
useradd dockeradmin

# Giving docker user a password
passwd dockeradmin

# Adding docker user to docker group
usermod -aG docker dockeradmin

Docker Demo

Use the following docker commands to achieve specific results

# List all running containers
docker ps

# List all containers
docker ps -a

# View all local images
docker images

# Download required image from docker repo
docker pull imagename:version

# Create a container and give shell
docker run -it --name containername imagename:version

# Start a container
docker start containername

# Stop a container
docker stop containername

# Get shell of a container
docker attach containername

# Remove a container
docker rm containername

# Remove an image locally
docker rmi imagename