How to install docker on CentOS / RHEL / Fedora

What is docker

Docker is a container-management system that helps us easily manage Linux Containers (LXC) in an easier and universal fashion. Docker is supported on many Linux platforms, such as RHEL, Ubuntu, Fedora, CentOS, Debian, Arch Linux, and so on. It is also supported on many cloud platforms, such as Amazon EC2, Rackspace Cloud, and Google Compute Engine.

Docker Editions

Docker is available in 2 editions namely:
1. Community Edition (CE): do-it-yourself, community supported version of Docker that’s available for free of cost.
2. Enterprise Edition (EE) : Officially supported and paid version from Docker.

Docker Terminologies

1. Docker Images : It is a collection of files like libraries, binaries, and other dependencies just needed to run the application. These files in the Docker image are read-only and hence the content of the image cannot be altered.
2. Docker Containers : The docker images are read-only and stateless. The docker containers on the other hand are spun-off from docker image and adds a read-write layer on top of it.
3. Docker Registry : Docker images can be stored in order to be publicly or privately in a Docker registry. Docker Registry could be hosted by a third party as a public or private registry, like Docker Hub.

Pre-requisites

Before installing docker engine, lets verify if you have all the pre-requisites met.
1. Docker is only supported on 64-bit architecture. So make sure you do not have a 32-bit system at hand. To check the architecture use the below command.

# uname -i
x86_64

2. Docker is supported on kernel version 3.8 or later. To check the kernel version, run the following command:

# uname -r
3.10.0-693.5.2.el7.x86_64

3. The kernel should have a storage backend such as DeviceMapper. To verify use either of the below commands.

# rpm -qa | grep mapper
device-mapper-1.02.140-8.el7.x86_64
device-mapper-libs-1.02.140-8.el7.x86_64

or

# grep device-mapper /proc/devices
253 device-mapper

Install the required packages

1. As specified in the pre-requisite section above, we need to have a storage backend such as DeviceMapper. device-mapper-persistent-data and lvm2 packages are required by the devicemapper storage driver.

# yum install -y device-mapper-persistent-data lvm2

2. Also install the yum-config-manager utility provided by yum-utils package in order to setup the docker repository in the next section.

# yum install -y yum-utils

Setup the repository

Use the command below to setup the repository for docker.

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

Installing docker

Finally coming to the last step of actaully installing the Community Edition of docker.

# yum install docker-ce

Installing Docker using an automated script

There also an automated way of installing docker, which installs the pre-requisite packages as well as the docker engine for you. The script is universal and works for all the linux distributions available. To install docker using the automated script use either of the below commands:

$ sudo curl -sSL https://get.docker.io/ | sh

or

sudo wget -qO- https://get.docker.io/ | sh

Start/Stop Docker service

You will have to start the docker service after you have finished installing docker engine.

# systemctl start docker

To enable the service start at boot time:

# systemctl enable docker

To stop the docker service, use the command below.

# systemctl stop docker

Verify installation

You can verify the docker installation by viewing the version of the docker engine installed by using either of the below commands.

# docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 17.10.0-ce
...
# docker --version
Docker version 17.10.0-ce, build f4ffd25

Update docker

To update docker to the latest version, you can use the yum update command.

# yum -y update docker
Related Post