Docker Install in RHEL | Red Hat Enterprise Linux

If you are using RHEL or Red Hat Enterprise Linux and trying to install Docker. Then I bet you have encountered this error:

Tried All mirror error

You can alternatively use podman though. But if you are stubborn like me and only want to use docker, then let’s do it-

Uninstall any leftover docker files:

As we tried and failed to install docker and now are here. We obviously have some unnecessary files left in our machine. But, if it’s the first time you are trying to install Docker then you don’t have to go through this 10 sec process but I recommend this. As it will take 10 sec from your valuable time but will give a clean clutter free installation.

It’s a simple single command we need to copy and paste in our terminal.

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine \
                  podman \

What we are doing here is we are deleting all the possible docker files may already existing in our machine.

it will get all the files and ask if we wanna continue it. Obviously we do, that’s the reason we typed this command (I mean, copy-paste) So, type yes or y and hit Enter it will do the process and show you how much storage we freed from those unnecessary files.

By the way, if there were no docker files from the first place you will see a report like none of these packages are installed. It’s OK, you were pure from the beginning. You can skip this next step.

We still have options to get more space from the old Docker/Podman installation. Cause Images, containers, volumes, and networks stored in /var/lib/docker/ aren’t automatically removed when you uninstall Docker.

So we are going to copy-paste few more commands One By One, to remove all those things-

sudo rm -rf /var/lib/docker /etc/docker
sudo rm /etc/apparmor.d/docker
sudo groupdel docker
sudo rm -rf /var/run/docker.sock

Now we have successfully removed docker from our system. Let’s do a reboot and start the installing process. For rebooting I know you know what the command you have to type still if you wanna copy paste this, here it is-
after a while the machine will reboot and we are going to login again.
Anyways, I hope we are logged back in. Now all we have to do is copy-paste bunch of commands and type y when it asks for it.

sudo yum install -y yum-utils


sudo yum-config-manager \
    --add-repo \

We will install the latest version of the docker-

sudo yum install docker-ce docker-ce-cli docker-compose-plugin

But if you want to install a specific version then use this command to list all the available repos (repositories)

yum list docker-ce --showduplicates | sort -r

You will see the available repos in this format-

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.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable

The list returned depends on which repositories are enabled, and is specific to your version of OS (indicated by the .el7 suffix in this example).

Install a specific version by its fully qualified package name, which is the package name (docker-ce) plus the version string (2nd column) starting at the first colon (:), up to the first hyphen, separated by a hyphen (-). For example, docker-ce-18.09.1.

Replace <VERSION_STRING> with the desired version and then run the following command to install:

sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> docker-compose-plugin

and Hit enter to install your desired version.

And now we are going to start our docker-

sudo systemctl start docker

and let’s say Hello to the world from docker to verify it’s installed correctly by running the hello-world image.

sudo docker run hello-world

This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.

Congratulations we have successfully installed Docker in our RHEL machine.

But we still have something to do, I really hope you use Passphrase only login with a nonroot user and your password only and root user access is disabled too. No? – ==You should and must do it==, here is How You Do It Trust me it makes your machine more secure and tough to hack or a brute-force attack.
So, as we are nonroot user, we still don’t have the required permission to work in docker. So, we need to create a docker group and add us there so we can use docker flawlessly.

To create the docker group and add your user:

Create the docker group-

sudo groupadd docker

Add your user to the docker group-

sudo usermod -aG docker $USER

Now let’s log out and log back in so that the group membership is re-evaluated.

You can also run the following command to activate the changes to groups:

newgrp docker

Verify that you can run docker commands without sudo. For that again we’ll say Hello to the world.

docker run hello-world

If you initially ran Docker CLI commands using sudo before adding your user to the docker group, you may see the following error:

WARNING: Error loading config file: /home/user/.docker/config.json – stat /home/user/.docker/config.json: permission denied

This error indicates that the permission settings for the ~/.docker/ directory are incorrect, due to having used the sudo command earlier.

To fix this problem, either remove the ~/.docker/ directory (it’s recreated automatically, ==but any custom settings are lost==, who cares! we just installed docker so no custom settings are there)

to remove the folder-

sudo rm -rf ~/.docker/ directory

or we can change its ownership and permissions using the following commands:

sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R

Now let’s Configure Docker to start on boot with systemd

Many modern Linux distributions use systemd to manage which services start when the system boots. Like on Debian and Ubuntu, the Docker service starts on boot by default. To automatically start Docker and containerd on boot for other Linux distributions like RHEL here that is using systemd, we need to run the following commands:

sudo systemctl enable docker.service
sudo systemctl enable containerd.service

Now if we don’t want it to run with boot, we just have to use disable instead of enable.

sudo systemctl disable docker.service
sudo systemctl disable containerd.service

And with this we are completely done with our Docker installation in our RHEL machine. Enjoy…

Leave a Reply

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