How to install docker on Redhat Linux (RHEL) and CentOS? How to setup the docker environment to start the first container to start exploring the container world? In this article, we are going to demonstrate the docker community edition deployment on RHEL/CentOS. We will also launch the Docker containers to test the deployment.
Docker Editions
- Docker Community Edition (CE) – Free, Community supported and Do it yourself model.
Docker Community Edition
- Docker Enterprise Edition – Supported by docker and it’s Paid version
Docker glossary
- Docker Image: Docker images are the basis of containers. An Image is an ordered collection of root filesystem changes and the corresponding execution parameters for use within a container runtime. An image typically contains a union of layered filesystems stacked on top of each other. An image does not have state and it never changes.
- Docker container: A container is a runtime instance of a docker image.
- Docker registry: A Registry is a hosted service containing repositories of images which response to the Registry API. The default registry can be accessed using a browser at Docker Hub or using the docker search command.
Pre-requisites:
1. Docker supports only x86_64 (64-bit architecture). It also required Linux kernel version 3.8 and above. You could verify the system architecture and kernel version using the following command.
[root@uaweb1 ~]# uname -ir 3.10.0-123.el7.x86_64 x86_64 [root@uaweb1 ~]#
2. Ensure that system is installed with following packages.
- device-mapper-libs
- device-mapper
- lvm2-libs
- lvm2
- device-mapper-persistent-data
- yum-utils
[root@uaweb1 ~]# rpm -qa | egrep "mapper|lvm2|device-mapper-persistent-data|yum-utils" device-mapper-event-libs-1.02.84-14.el7.x86_64 device-mapper-libs-1.02.84-14.el7.x86_64 lvm2-libs-2.02.105-14.el7.x86_64 device-mapper-persistent-data-0.3.2-1.el7.x86_64 lvm2-2.02.105-14.el7.x86_64 device-mapper-1.02.84-14.el7.x86_64 device-mapper-event-1.02.84-14.el7.x86_64 yum-utils-1.1.31-24.el7.noarch [root@uaweb1 ~]#
If not, please install the missing packages using yum command.
# yum install -y device-mapper-persistent-data lvm2 device-mapper yum-utils
Setting up the Docker Repository:
Configure the docker repository by pulling the repo file form docker website and save it in /etc/yum.repos.d directory. The following command does all the actions for you.
[root@uaweb1 yum.repos.d]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo Loaded plugins: langpacks, product-id adding repo from: https://download.docker.com/linux/centos/docker-ce.repo grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo [root@uaweb1 yum.repos.d]#
Note: Docker community edition is not available for RHEL. However, Docker provides the community edition for Centos which also can be installed on RHEL. But it’s unsupported.
Installing Docker:
Once the repo is configured successfully, we are good to install docker community edition.
# yum install docker-ce
You might get following errors on Redhat Enterprise Linux (RHEL)
Error: Package: docker-ce-18.03.1.ce-1.el7.centos.x86_64 (docker-ce-stable)
Requires: pigz
Error: Package: docker-ce-18.03.1.ce-1.el7.centos.x86_64 (docker-ce-stable)
Requires: container-selinux >= 2.9
You could try using –skip-broken to work around the problem
You could try running: rpm -Va –nofiles –nodigest
To fix above mentioned error,
Redhat Linux (RHEL 7) requires extra rpms. Enable the extras RHEL repository. This ensures access to the container-selinux package which is required by docker-ce. It requires a Red hat subscription.
# yum-config-manager --enable rhel-7-server-extras-rpms
Start the Docker service
Once the installation is done, you need to start the docker service manually.
[root@node1 ~]# systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: https://docs.docker.com [root@node1 ~]# systemctl start docker [root@node1 ~]#
To start the docker service on startup,
[root@node1 ~]# systemctl enable docker Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service. [root@node1 ~]# systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2018-06-15 11:31:43 PDT; 21s ago Docs: https://docs.docker.com Main PID: 1598 (dockerd) CGroup: /system.slice/docker.service ├─1598 /usr/bin/dockerd └─1602 docker-containerd --config /var/run/docker/containerd/containerd.toml
Verify the docker Installation:
The most common way to test the docker is, running image “hello-world” .
[root@node1 ~]# docker run -it hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 9bb5a5d4561a: Pull complete Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/ [root@node1 ~]#
We have successfully installed docker community edition on RHEL/CentOS.
Noe Albarez says
Thanks, I can install the docker following your precise instruction.
Thanks again.