In the latest version of RHEL 8 / CentOS 8, Red Hat has built its own tools, buildah
and podman
. These tools are compatible with existing docker images and do not need to interact with the daemon when working. They allow containers to be created like normal users, without the need to apply for special permissions. (There are still some restrictions: for example, when writing an article, without permission, you still cannot map the container port.)
Some special tools, no matter what, are still missing: docker-compose
, which does not yet exist. In this tutorial, we will take a look at how to install and run the original Docker CE on Rhel8 by using the official Docker source repository for CentOS7.
In this tutorial, you will learn:
Category: | Software requirements, conventions, and versions used |
---|---|
System: | RHEL 8 / CentOS 8 |
Software: | Docker version 18.09.2 |
Others: | With root privileges, you can run related commands |
Convention: | #-The commands given require root privileges to execute. The root user executes directly, and the ordinary user adds sudo execution. $-The given command can be executed by normal users |
Docker is an open source project that allows you to bundle application creation and release with containers. The container is a standardized environment that is independent of the host system and can be easily replicated. In Red Hat Enterprise Linux 7, Docker is officially supported. At the same time, Red Hat independently developed a series of tools: buildah
and podman
to support Docker.
By using third-party source repositories, we can also install Docker CE (community version). In this guide, we will install this source repository. Please note that for CentOS 7
(a RHEL clone), this means that there is no official support like Red Hat Enterprise Linux. Because of this, there is a problem-we will discuss it in detail later.
Because Docker is not yet available in RHEL 8 / CentOS 8, we need to add third-party sources to obtain this software. Here we will use the official Docker CE CentOS source: at the time of writing this article, this is the only way to install Docker CE on RHEL 8 / CentOS 8.
The dnf config-manager
tool allows us to easily enable or disable a source in our Linux distribution without worrying about other trivial matters. By default, only appstream
and baseos
sources are enabled on Rhel8. We need to add and enable the docker-ce
source. In order to accomplish this task, all we need to do is to run the following command:
$ sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
We can verify whether this source is successfully enabled by viewing the output of the following command.
$ sudo dnf repolist -v
This command will return detailed information of all enabled source repositories by default. At this point you may see the following output:
Repo-id : docker-ce-stable
Repo-name : Docker CE Stable - x86_64
Repo-revision:1549905809
Repo-updated : Mon 11 Feb 201906:23:29 PM CET
Repo-pkgs :30
Repo-size :618 M
Repo-baseurl : https://download.docker.com/linux/centos/7/x86_64/stable
Repo-expire :172,800second(s)(last: Mon 18 Feb 201910:23:54 AM CET)
Repo-filename:/etc/yum.repos.d/docker-ce.repo
Repo-id : rhel-8-for-x86_64-appstream-rpms
Repo-name : Red Hat Enterprise Linux 8for x86_64 - AppStream Beta(RPMs)
Repo-revision:1542158694
Repo-updated : Wed 14 Nov 201802:24:54 AM CET
Repo-pkgs :4,594
Repo-size :4.9 G
Repo-baseurl : https://cdn.redhat.com/content/beta/rhel8/8/x86_64/appstream/os
Repo-expire :86,400second(s)(last: Mon 18 Feb 201910:23:55 AM CET)
Repo-filename:/etc/yum.repos.d/redhat.repo
Repo-id : rhel-8-for-x86_64-baseos-rpms
Repo-name : Red Hat Enterprise Linux 8for x86_64 - BaseOS Beta(RPMs)
Repo-revision:1542158719
Repo-updated : Wed 14 Nov 201802:25:19 AM CET
Repo-pkgs :1,686
Repo-size :925 M
Repo-baseurl : https://cdn.redhat.com/content/beta/rhel8/8/x86_64/baseos/os
Repo-expire :86,400second(s)(last: Mon 18 Feb 201910:23:56 AM CET)
Repo-filename:/etc/yum.repos.d/redhat.repo
Total packages:6,310
The docker-ce-stable
source is now enabled on your system. This source repository contains several versions of the docker-ce
package. To display them, we can run:
$ dnf list docker-ce --showduplicates | sort -r
docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
Which version do we want to install? When the version number of containerd.io
that docker-ce
depends on is greater than 1.2.0-3.el7
, the installation process is terminated for unknown reasons. Therefore, simply running the sudo dnf install docker-ce
command will not work properly. After solving this problem, we will encounter another problem. Because the system firewall manager firewalld
is enabled, DNS resolution
in the Docker container will not work properly.
Of course, this is a serious problem. However, anyway, if you want to continue installing Docker, here are some ways to avoid dependency problems:
docker-ce
, these versions of docker only require the installable containerd.io
package--nobest
option, the installation process is forced to proceed.containerd.io
rpm packageAt the time of writing this article, the version of docker-ce
that can be installed without problems is:
To install a specific version, we only need to provide the full name of the package, for example:
$ sudo dnf install docker-ce-3:18.09.1-3.el7
Normally, when installing a package, the best available version is selected from the source repository. In this example, we tried to install the latest version of docker-ce
, but failed. By using the --nobest
option, we can change this behavior so that the first docker-ce
version that meets the dependency conditions is selected. Here, we have selected 3:18.09.1-3.el7
.
$ sudo dnf install --nobest docker-ce
Dependencies resolved.
Problem:package docker-ce-3:19.03.2-3.el7.x86_64 requires containerd.io >=1.2.2-3, but none of the providers can be installed
- cannot install the best candidate for the job
- package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
- package containerd.io-1.2.2-3.el7.x86_64 is excluded
- package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
=======================================================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================================================
Installing:
docker-ce x86_64 3:18.09.1-3.el7 docker-ce-stable 19 M
Installing dependencies:
containerd.io x86_64 1.2.0-3.el7 docker-ce-stable 22 M
docker-ce-cli x86_64 1:19.03.2-3.el7 docker-ce-stable 39 M
container-selinux noarch 2:2.94-1.git1e99f1d.module+el8.0.0+4017+bbba319f rhel-8-for-x86_64-appstream-rpms 43 k
tar x86_64 2:1.30-4.el8 rhel-8-for-x86_64-baseos-rpms 838 k
libcgroup x86_64 0.41-19.el8 rhel-8-for-x86_64-baseos-rpms 70 k
python3-policycoreutils noarch 2.8-16.1.el8 rhel-8-for-x86_64-baseos-rpms 2.2 M
python3-libsemanage x86_64 2.8-5.el8 rhel-8-for-x86_64-baseos-rpms 127 k
python3-setools x86_64 4.2.0-2.el8 rhel-8-for-x86_64-baseos-rpms 598 k
checkpolicy x86_64 2.8-2.el8 rhel-8-for-x86_64-baseos-rpms 338 k
python3-audit x86_64 3.0-0.10.20180831git0047a6c.el8 rhel-8-for-x86_64-baseos-rpms 85 k
policycoreutils-python-utils noarch 2.8-16.1.el8 rhel-8-for-x86_64-baseos-rpms 228 k
Skipping packages with broken dependencies:
docker-ce x86_64 3:19.03.2-3.el7 docker-ce-stable 24 M
Transaction Summary
=======================================================================================================================================================
Install 12 Packages
Skip 1 Package
Total download size:85 M
Installed size:351 M
Is this ok [y/N]:
If we need to install the latest version of docker-ce
, we can manually install containerd.io
according to the required version number, and run:
$ sudo dnf install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
After the installation of this package is complete, we can easily install the latest docker-ce
:
$ sudo dnf install docker-ce
Dependencies resolved.=======================================================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================================================
Installing:
docker-ce x86_64 3:19.03.2-3.el7 docker-ce-stable 24 M
Installing dependencies:
docker-ce-cli x86_64 1:19.03.2-3.el7 docker-ce-stable 39 M
tar x86_64 2:1.30-4.el8 rhel-8-for-x86_64-baseos-rpms 838 k
libcgroup x86_64 0.41-19.el8 rhel-8-for-x86_64-baseos-rpms 70 k
Transaction Summary
=======================================================================================================================================================
Install 4 Packages
Total download size:65 M
Installed size:275 M
Is this ok [y/N]:
This choice is not convenient because containerd.io
is not installed as a dependency of docker-ce
. If you uninstall Docker from the system in the future, containerd.io
will not be removed automatically.
No matter what method we use to install docker-ce
, as we said earlier, in order to ensure the normal operation of DNS resolution
inside the Docker container, we need to disable firewalld (this may require a system restart)
$ sudo systemctl disable firewalld
Once the docker-ce
installation is complete, we must start and enable the Docker daemon. By doing this, the next time the system starts, Docker will follow the system to start automatically. We need to run the following command:
$ sudo systemctl enable --now docker
At this point, we confirm whether the daemon is running normally by running the following command:
$ systemctl is-active docker
active
Similarly, we can also run the following command to confirm whether it will start with the system:
$ systemctl is-enabled docker
enabled
Docker compose is a very useful software package that allows us to manage multiple container applications. For example, for applications based on LAMP
, every part of the environment (PHP, Apache, MariaDB) is provided by a clear container. This package is not available in Rhel8, and there is no similar Rhel tools available. In any case, we have many ways to install it: please read on and choose the one that suits you:
How we should install docker-compose
depends on whether we want to install it globally or just for a single user. At the time of writing this article, the only way to install globally is to download the binary package from the project’s Github page:
$ curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)"-o docker-compose
Once the binary package is downloaded, we move it to the /usr/local/bin
directory and make it executable.
$ sudo mv docker-compose /usr/local/bin && sudo chmod +x /usr/local/bin/docker-compose
This /usr/local
is not randomly selected. This directory is used to store software manually installed by local administrators (such as software compiled from source code), and to ensure separation from the software installed by the system software manager.
Although an ordinary user can run docker-related commands if they join the docker
user group (this group is automatically created when docker-ce is installed), but for security reasons, they must run with root privileges. Because /usr/local/bin
is not in the root user's PATH
environment variable, we need to specify the location of the binary software, or add /usr/local/bin
to the PATH
. Here we recommend the previous way.
If our user is a member of the docker
user group, we can run the docker command. Because docker-compose
h also provides a python package, we can also use pip
to install it. First confirm that pip has been installed:
$ sudo dnf install python3-pip
To get docker-compose, we run:
$ pip3.6 install docker-compose --user
Please note that even if we can use root to run pip to install this package globally (docker-compose), this approach is not recommended and not encouraged.
We installed docker and docker-compose, and now check that everything is running as expected. We can try to build an image and run a container. Here we use the official httpd
mirror. All we need to do is to run the following command:
sudo docker run --rm --name=linuxconfig-test -p 80:80 httpd
Because the httpd
mirror does not exist locally, it will be automatically acquired and built. Finally, a container based on it is running in the foreground (it will be automatically removed when it stops). When we enter the local ip on the browser of the local computer, we should see the message "It works!".
Red Hat Enterprise Linux 8 does not support Docker: On this release, Docker has been replaced by Red Hat's own tools buildah
and podman
. These tools are compatible with Docker, but do not require a server/client architecture to run. Using local tools is usually a recommended way, but for some reason you still want to install the original Docker. In this tutorial, we saw how to install Docker CE
(100% compatible) on Rhel8 using the official source repository for CentOS 7 made by Docker.
This is not a perfect solution. Sometimes we need to do it manually to ensure that Docker runs normally on RHEL8. If a problem is found during use, or a better solution is found, we will update this article.
Recommended Posts