Installation Steps of Docker CE on CentOS 8/RHEL 8 Server
Step:1) Enable Docker CE Repository
[root@docker-ce ~]# dnf config-manager –add repo=https://download.docker.com/linux/centos/docker-ce.repo
Step:2) Install Docker CE using dnf command
[root@docker-ce ~]# dnf repolist -v
or
[root@docker-ce ~]# dnf list docker-ce –showduplicates | sort -r
Step:3) Install Docker CE using dnf command
Error:
Problem: package docker-ce-3:19.03.5-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
Install the latest available containerd.io package manually
[root@docker-ce ~]# 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 package is installed, we can simply install the latest docker-ce
[root@docker-ce ~]# dnf install docker-ce
Whatever method we use to install docker-ce
, as said before, in order to make DNS resolution
work inside Docker containers, we must disable firewalld (a system reboot may be also needed):
$ sudo systemctl disable firewalld
Start and enable the docker daemon
Once docker-ce
is installed, we must start and enable the docker daemon, so that it
will be also launched automatically at boot. The command we need to run
is the following:
$ sudo systemctl enable --now docker
At this point, we can confirm that the daemon is active by running:
$ systemctl is-active docker
active
Similarly, we can check that it is enabled at boot, by running:
$ systemctl is-enabled docker
enabled
Installing docker-compose
Docker compose is a very useful package which let us manage multi-container applications, like for example those based on the LAMP
stack, where each part of the environment (PHP, Apache, MariaDB) is
provided by a dedicated container (if you are interested in the subject,
take a look at our tutorial about creating a docker-based lamp stack).
The package is not available on Rhel8, nor an equivalent exists to be
used with the Rhel tools. It’s, however, possible to install it in many
ways: just keep on reading and decide what suits you best.
Global installation
The way we should install docker-compose
varies depending on whether we want to install it globally or just for a
single user. At the moment of writing, the only way to install it
globally is to download the binary from the github page of the project:
$ curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o docker-compose
Once the binary is downloaded, we move it into /usr/local/bin
and we make it executable:
$ sudo mv docker-compose /usr/local/bin && sudo chmod +x /usr/local/bin/docker-compose
The /usr/local
hierarchy is not chosen randomly. This directory structure is made to
be used for files installed by the local administrator manually (for
software compiled from source, for example), in order to ensure
separation from the software installed with the system package manager.
Although it’s possible for a normal user to run docker-related commands if he is part of the docker
group (the group is automatically created when we install docker-ce),
by default they must be executed with root privileges for security
reasons. When we need to do the latter, since the /usr/local/bin
directory is not in the root user’s PATH
, we either need to call the binary specifying its location or add /usr/local/bin
to the PATH
itself. The first option is the one which I recommend in this case.
Per-user installation
If our user is part of the docker
group, and thus it is allowed to run docker commands, and since docker-compose
is available as a python package, we can also install it using pip
, the python package manager. First, make sure pip itself is installed:
$ sudo dnf install python3-pip
To obtain docker-compose we run:
$ pip3.6 install docker-compose --user
Please
notice that even if would be possible to run pip as root to install a
package globally, this is not recommended and highly discouraged.
Testing docker
We
installed docker and docker-compose, now to check that everything works
as expected, we can try to build an image and run a container: in this
case we will use the official httpd
one. All we have to do is to launch the following command:
sudo docker run --rm --name=linuxconfig-test -p 80:80 httpd
Since the httpd
image does not exists locally it will be automatically fetched and
built. Finally, a container based on it will be launched in the
foreground (it will be automatically removed when stopped). We should be
able to see the It works!
message when we reach our machine ip via browser.
Conclusions
Red Hat Enterprise Linux 8 does not support Docker: on this distribution it has been replaced by Red Hat own tools like buildah
and podman
,
which are compatible with Docker but don’t need a server/client
architecture to run. Using native tools, where possibile, is always the
recommended way to go, but for a reason or another you may still want to
install the original Docker. In this tutorial, we saw how it is
possible to install Docker CE
on Rhel8, by using the official Docker repository for CentOS7, which is a 100% compatible clone.