Red Hat

How to install Docker in RHEL 7.x

Posted on

As in Docker documentation, they do not support Docker in Red Hat Enterprise Linux system.

To use Docker in RHEL, you need maintained CentOS version. Archived version is not supported.

Uninstall Old Docker Version

First you need to uninstall any old Docker version if exist.

yum remove docker \                  docker-client \                  docker-client-latest \                  docker-common \                  docker-latest \                  docker-latest-logrotate \                  docker-logrotate \                  docker-engine
Uninstall Old Docker version

The contents of /var/lib/docker/, including images, containers, volumes, and networks, are preserved. The Docker CE package is now called docker-ce

Install Using Repository

You need to install install required package before install Docker repos. yum-config-manager will be needed and available in yum-utils package.

sudo yum install -y yum-utils \  device-mapper-persistent-data \  lvm2

Then, add docker repository using yum-config-manager.

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

Install Docker-CE

To install latest docker ce, append this command in bash.

sudo yum install docker-ce docker-ce-cli containerd.io

Sometimes, there are maybe you are stuck with some error with Docker installation in RHEL 7, such as policycoreutils dependency as below:

Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-managerThis system is not registered with an entitlement server. You can use subscription-manager to register.Loading mirror speeds from cached hostfiledocker-ce-stable                                                                         | 3.5 kB  00:00:00(1/2): docker-ce-stable/x86_64/primary_db                                                |  28 kB  00:00:00(2/2): docker-ce-stable/x86_64/updateinfo                                                |   55 B  00:00:00Resolving Dependencies--> Running transaction check---> Package containerd.io.x86_64 0:1.2.5-3.1.el7 will be installed---> Package docker-ce.x86_64 3:18.09.6-3.el7 will be installed--> Processing Dependency: container-selinux >= 2.9 for package: 3:docker-ce-18.09.6-3.el7.x86_64--> Processing Dependency: libcgroup for package: 3:docker-ce-18.09.6-3.el7.x86_64---> Package docker-ce-cli.x86_64 1:18.09.6-3.el7 will be installed--> Running transaction check---> Package container-selinux.noarch 2:2.95-2.el7_6 will be installed--> Processing Dependency: policycoreutils-python for package: 2:container-selinux-2.95-2.el7_6.noarch---> Package libcgroup.x86_64 0:0.41-20.el7 will be installed--> Running transaction check---> Package policycoreutils-python.x86_64 0:2.5-29.el7 will be installed--> Processing Dependency: policycoreutils = 2.5-29.el7 for package: policycoreutils-python-2.5-29.el7.x86_64--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-29.el7.x86_64--> Processing Dependency: libsemanage-python >= 2.5-14 for package: policycoreutils-python-2.5-29.el7.x86_64--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-29.el7.x86_64--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-29.el7.x86_64--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-29.el7.x86_64--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-29.el7.x86_64--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-29.el7.x86_64--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-29.el7.x86_64--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-29.el7.x86_64--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-29.el7.x86_64--> Running transaction check---> Package audit-libs-python.x86_64 0:2.8.4-4.el7 will be installed---> Package checkpolicy.x86_64 0:2.5-8.el7 will be installed---> Package libsemanage-python.x86_64 0:2.5-14.el7 will be installed---> Package policycoreutils-python.x86_64 0:2.5-29.el7 will be installed--> Processing Dependency: policycoreutils = 2.5-29.el7 for package: policycoreutils-python-2.5-29.el7.x86_64---> Package python-IPy.noarch 0:0.75-6.el7 will be installed---> Package setools-libs.x86_64 0:3.3.8-4.el7 will be installed--> Finished Dependency ResolutionError: Package: policycoreutils-python-2.5-29.el7.x86_64 (centos)           Requires: policycoreutils = 2.5-29.el7           Installed: policycoreutils-2.5-29.el7_6.1.x86_64 (@RedHatEnterpriseLinux7ServerRPMs/7Server)               policycoreutils = 2.5-29.el7_6.1           Available: policycoreutils-2.5-29.el7.x86_64 (centos)               policycoreutils = 2.5-29.el7 You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest
Complaining about policycoreutils doesn’t match the dependencies version.

The workarounds, you need to uninstall existing policycoreutils and install needed package.

[[email protected] ~]# yum remove policycoreutilsLoaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-managerThis system is not registered with an entitlement server. You can use subscription-manager to register.Resolving Dependencies--> Running transaction check---> Package policycoreutils.x86_64 0:2.5-29.el7_6.1 will be erased--> Processing Dependency: policycoreutils for package: authconfig-6.2.8-30.el7.x86_64--> Running transaction check---> Package authconfig.x86_64 0:6.2.8-30.el7 will be erased--> Finished Dependency ResolutionDependencies Resolved================================================================================================================ Package               Arch         Version               Repository                                       Size================================================================================================================Removing: policycoreutils       x86_64       2.5-29.el7_6.1        @RedHatEnterpriseLinux7ServerRPMs/7Server       5.1 MRemoving for dependencies: authconfig            x86_64       6.2.8-30.el7          @RedHatEnterpriseLinux7ServerRPMs/7Server       2.2 MTransaction Summary================================================================================================================Remove  1 Package (+1 Dependent package)Installed size: 7.3 MIs this ok [y/N]: yDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transaction  Erasing    : authconfig-6.2.8-30.el7.x86_64                                                               1/2warning: /etc/sysconfig/authconfig saved as /etc/sysconfig/authconfig.rpmsave  Erasing    : policycoreutils-2.5-29.el7_6.1.x86_64                                                        2/2Loading mirror speeds from cached hostfile * epel: epel.dionipe.id  Verifying  : policycoreutils-2.5-29.el7_6.1.x86_64                                                        1/2  Verifying  : authconfig-6.2.8-30.el7.x86_64                                                               2/2Removed:  policycoreutils.x86_64 0:2.5-29.el7_6.1Dependency Removed:  authconfig.x86_64 0:6.2.8-30.el7Complete!

Install needed package dependencies.

[[email protected] ~]# rpm -ivh http://mirror.centos.org/centos/7/os/x86_64/Packages/policycoreutils-2.5-29.el7.x86_64.rpmRetrieving http://mirror.centos.org/centos/7/os/x86_64/Packages/policycoreutils-2.5-29.el7.x86_64.rpmPreparing...                          ################################# [100%]Updating / installing...   1:policycoreutils-2.5-29.el7       ################################# [100%]

Run, yum update and try to install Docker again.

Other error, when you try to install docker-ce with:

sudo yum install docker-ce docker-ce-cli containerd.io

, it will complaining you with Requires: container-selinux >= 2.9 stuff.

[[email protected] ~]# yum install -y docker-ceLoaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-managerThis system is not registered with an entitlement server. You can use subscription-manager to register.Loading mirror speeds from cached hostfile * epel: epel.dionipe.id * rpmfusion-free-updates: fr2.rpmfind.net * rpmfusion-nonfree-updates: fr2.rpmfind.net * webtatic: uk.repo.webtatic.comResolving Dependencies--> Running transaction check---> Package docker-ce.x86_64 3:18.09.3-3.el7 will be installed--> Processing Dependency: container-selinux >= 2.9 for package: 3:docker-ce-18.09.3-3.el7.x86_64--> Processing Dependency: containerd.io >= 1.2.2-3 for package: 3:docker-ce-18.09.3-3.el7.x86_64--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-18.09.3-3.el7.x86_64--> Processing Dependency: libcgroup for package: 3:docker-ce-18.09.3-3.el7.x86_64--> Running transaction check---> Package containerd.io.x86_64 0:1.2.4-3.1.el7 will be installed---> Package docker-ce.x86_64 3:18.09.3-3.el7 will be installed--> Processing Dependency: container-selinux >= 2.9 for package: 3:docker-ce-18.09.3-3.el7.x86_64---> Package docker-ce-cli.x86_64 1:18.09.3-3.el7 will be installed---> Package libcgroup.x86_64 0:0.41-20.el7 will be installed--> Finished Dependency ResolutionError: Package: 3:docker-ce-18.09.3-3.el7.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

This tutorial will guide you to install contanainer-selinux in Red Hat Enterprise Linux system.

Create repository to point CentOS repo. Create a file in /etc/yum.repos.d and name it centos.repo and add below repository resource.

# Create new repo to enable CentOS[centos]name=CentOS-7baseurl=http://ftp.heanet.ie/pub/centos/7/os/x86_64/enabled=1gpgcheck=1gpgkey=http://ftp.heanet.ie/pub/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7

Run yum repolist.

# yum repolistLoaded plugins: product-id, search-disabled-repos, subscription-managerThis system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.centos                                                                                                        | 3.6 kB  00:00:00(1/2): centos/group_gz                                                                                        | 166 kB  00:00:00(2/2): centos/primary_db                                                                                      | 6.0 MB  00:00:01repo id                                         repo name                                                                      statuscentos                                          CentOS-7                                                                       10,019docker-ce-stable/x86_64                         Docker CE Stable - x86_64                                                          36*epel/x86_64                                    Extra Packages for Enterprise Linux 7 - x86_64                                 12,974ius/x86_64                                      IUS Community Packages for Enterprise Linux 7 - x86_64                            570server                                          server_repo                                                                     4,620webtatic/x86_64                                 Webtatic Repository EL7 - x86_64                                                  341repolist: 28,560

Run yum update.

 # yum update

Then, install container-selinux from CentOS mirror site. Change the version to the latest listed in this site.

yum install -y http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.74-1.el7.noarch.rpm

This will install container-selinux with its dependencies smoothly.

Then the best part, we will install Docker CE with this command line again.

yum install -y docker-ce docker-ce-cli containerd.io

After the installation completed, you need to enable docker service.

Run below command.

systemctl enable docker

systemctl start docker

Now, you can run docker run to check if docker works.

# docker run hello-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-world1b930d010525: Pull completeDigest: sha256:0e11c388b664df8a27a901dce21eb89f11d8292f7fca1b3e3c4321bf7897bffeStatus: Downloaded newer image for hello-world:latestHello 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 bashShare images, automate workflows, and more with a free Docker ID: https://hub.docker.com/For more examples and ideas, visit: https://docs.docker.com/get-started/

How to Install Docker Compose

For linux user you can follow below steps.

sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Add executable permission to binary.

sudo chmod +x /usr/local/bin/docker-compose

You can also add symbolic links to /usr/bin or any other path.

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Run following command to check whether compose is available to use.

$ docker-compose --version

One thought on “How to install Docker in RHEL 7.x

Leave a Reply

Your email address will not be published. Required fields are marked *