Installing Docker on Ubuntu and CentOS


In this post I will follow the latest official docker steps to install docker engine from docker apt repository on Ubuntu and CentOS.

Installing docker engine on Ubuntu

I have spawned an Ubuntu server on cloud hosting and will connect with SSH to the machine. It is a fresh server of Ubuntu.

Uninstall old versions

As per the instructions we have to ensure that any conflicting packages are uninstalled.

for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done

Set up the repository

  1. Update the apt package index and install packages to allow apt to use a repository over HTTPS

sudo apt-get updatesudo apt-get install ca-certificates curl gnupg

  1. Add Docker’s official GPG key:
sudo install -m 0755 -d /etc/apt/keyrings

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

sudo chmod a+r /etc/apt/keyrings/docker.gpg
  1. Use the following command to set up the repository:

echo \

"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \

"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \

sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker Engine

  1. Update the apt package index:
 sudo apt-get update

2. Install Docker Engine, containerd, and Docker Compose latest version.

To install the latest version, run:

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  1. Verify that the Docker Engine installation is successful by running the hello-world image.
sudo docker run hello-world

This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.

You have now successfully installed and started Docker Engine.

Installing docker on CentOS

I am using CentOS 8.3 to install Docker version 4.11. The CentOS VM is provisioned on Azure cloud. I will follow the recommended installation method to install from docker repository from official docker installation guide.

Prerequisites

Checking the pre-requisites required for docker to be installed on any environment.

yum-utils, device-mapper-persistent-data and lvm2

Setting up the Docker repo

Install the yum-utils package (which provides the yum-config-manager utility) and set up the repository.

sudo yum install -y yum-utils

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Install docker latest version

1- To install Docker Engine, containerd, and Docker Compose latest version run the below.

sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

2- Start and enable docker service

sudo systemctl start docker

3- Run a hello-world image container to test the installation

sudo docker run hello-world

A Beginner’s Guide to Containerization and Docker’s Core Concepts


Containerization has become the standard for modern software development cycle and delivery where agile delivery methods are required to keep up with the demand and pace of requirements and needs. Delivery time is not only the advantage that containerization offers but uniformity of code & packaging of software with all of its dependencies, environment & configuration has resolved the developers “works on my machine” dilemma. Containers have become the building blocks of micro services architecture on which all the modern applications are based and deployed in the cloud.

Docker has become the de facto standard to build & share containerized applications from development environments to cloud making containers ubiquitous. Although Kubernetes latest version have removed support for Docker container runtime but still docker remains favorite for collaboration, packaging and image distribution for developers. This post encapsulates the brief coverage of Docker’s concepts, components, images, containers, and Docker Hub. It emphasizes the transformative nature of Docker and appeals to beginners who are embarking on a journey to explore containerization and images.

Docker architecture and components

Docker architecture and components


Docker file and docker compose

A docker file is a set of instructions in a text file which is used to define an image and pass runtime values, configurations & instructions (RUN, COPY etc.) to the container during initializing it. It is done on a single isolated environment.

Docker compose is a tool that defines a YAML file for multi-container based applications that defines the volumes, services, networks and configurations. This makes the workflow of your application that is based on multiple containers to initialize, run and manage the lifecycle of with a single command (docker-compose up, docker-compose down).

Docker Images

As stated above the docker file is built into an image which acts as a set of instructions and blueprint for creating docker containers. It is an executable package with all the dependencies, libraries, runtime and code required to run the container.

Docker client

The Docker client/Docker CLI is a command line tool available for various operating systems (Linux, macOS, Windows) and is a crucial tool for developers, system administrators, and DevOps teams that allows them to interact with the Docker daemon.

Docker daemon/Engine and containerd

Docker daemon/engine used interchangeably is the core component of the Docker platform responsible for management of containers, images, networking, storage, security and isolation. Containerd, on the other hand, is an open-source container runtime officially a graduated project within the Cloud Native Computing Foundation. Containerd executes containers based on OCI (Open Container Initiative) specifications, ensuring compatibility and interoperability with other container runtimes and tools. Containerd executes containers based on OCI (Open Container Initiative) specifications, ensuring compatibility and interoperability with other container runtimes and tools.

Docker hub & registry

A Docker registry is a central repository that stores Docker images. It serves as a distribution hub where users can publish, share, and pull Docker images for use in their environments.
Docker Hub is the default public Docker registry provided by Docker. It hosts a vast collection of pre-built Docker images contributed by the community and official repositories for popular software and services. Docker Hub allows users to search for, pull, and push Docker images.

However, organizations can setup their private registries to store and manage their sensitive and proprietary images. Apart from Docker Hub, there are other third-party Docker registries available, such as Amazon Elastic Container Registry (ECR), Google Container Registry (GCR), and Azure Container Registry (ACR).

Docker desktop

Docker Desktop is an application for Linux, Windows and MacOS that provides an easy-to-use and streamlined experience for developers to build, test, and deploy containerized applications on their local machines. It abstracts away the complexities of setting up and configuring Docker components individually, providing a unified and integrated experience for containerized application development and testing.

The docker desktop includes all the components (Docker engine, CLI, container management, docker swarm, building images, networking, storage and resource management) on the developer’s computer.

Conclusion:

Docker has revolutionized software development by simplifying the creation, distribution, and deployment of containerized applications. It offers unparalleled benefits, including faster development cycles, collaboration, scalability, and compatibility across different environments. By embracing Docker’s concepts, components, and tools like Dockerfile, Docker Compose, and Docker Hub, developers can enhance their workflow and unlock the true potential of containerization in today’s fast-paced software industry.