Docker installation on Linux

Docker installation on Linux

Docker is a platform that simplifies the development, deployment, and running of applications by using containers. These containers are like standardized, portable units of software that package up everything an application needs to run, including its code, libraries, system tools, and settings. We shall use the shipping containers for example. The way things are packaged inside the container, is the same way developer will put his code inside the container. The way the containers are handled in the ports, the containers will be handled easily by DevOps environment. This tutorial is about installation of Docker on Linux.

Updating software packages on your system to the latest available versions, first.

# yum update

What is KVM?

It is the Linux kernel module enabling hardware virtualization capabilities. It allows creating full virtual machines (VMs) that run a complete operating system isolated from the host. Requires CPU support for hardware virtualization (VT-x on Intel, AMD-V on AMD). The KVM module should load automatically if the host has virtualization support. To load the module manually, run:

# modprobe kvm

My VM uses Intel based processor. Hence let’s use a suitable parameters.

# modprobe kvm_intel
modprobe: ERROR: could not insert 'kvm_intel': Operation not supported

The CPU of my VM does not support KVM. Hence the commands are failing.

# kvm-ok
-bash: kvm-ok: command not found

Is KVM necessary to run Docker CE?

Docker CE utilizes containerization which isolates processes but shares the host kernel, while KVM enables full virtualization with separate operating systems per VM. Docker Desktop for Linux requires KVM or other hypervisors (like VirtualBox) for features like desktop integration and graphical interfaces. Docker on servers works without KVM, just needing compatible Linux kernel and resources. So, let’s not worry about that. Let’s try to install Docker Community Edition (CE) on Linux CentOS server O/S.

Installation of Docker

# sudo yum install -y yum-utils

Add the docker repository to the CentOS’s list of known repositories.

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

Install the Docker

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

Start the Docker service

# sudo systemctl start docker

Verify if Docker is installed properly and it is able to run the hello-world container.

# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:4bd78111b6914a99dbc560e6a20eab57ff6655aea4a80c50b0c5491968cbc2e6
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

You have now successfully installed and started Docker Engine.

Run Docker as non-root user

We can not be using root or super user for all operations. Hence creating a dedicated user for Docker is necessary.

# useradd -m -d /opt/docker docker

This will create a user docker with /opt/docker as his home folder

# sudo groupadd docker

This adds a docker group

# sudo usermod -aG docker docker

This adds the user to docker group

# sudo su - docker

We login as docker user

$ id
uid=1000(docker) gid=1000(docker) groups=1000(docker) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

Lets ensure we are able to run the container without any permission issues.

$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

Yes. The container is running without any issues.

This post is written as part of #WriteAPageADay campaign of BlogChatter