Docker is an open-source and modern top-rated platform, used to create, distribute, operate, and ship software applications using docker containers. Like virtual machines, Docker containers assist in separating the applications from the rest system. It becomes simple to create a software app, pack it in a container with all of its dependencies, and deliver it anywhere
In this tutorial, we will explore how to install Docker on CentOS 8 using the command line.
Methods to install Docker on CentOS 8
Docker can install on CentOS 8 system by using a couple of ways, depending on your requirements:
- The recommended approach to install docker on CentOS is by using docker’s repositories. You can set up these repositories on your system and install docker using them. Further, you can also upgrade it.
- Alternatively, you can download the docker’s RPM package and install it manually on your system. In this approach, you will need to manage all upgrades manually. This installation method is useful when installing docker on security measures systems without internet access.
- In development and testing environments, you can install docker using automated scripts.
Here, we will install Docker on our Linux system from Docker’s repository. Follow the below steps to install Docker on CentOS 8 using Docker’s repository:
Step 1: Add Docker’s Repository on CentOS 8
First, add the docker’s repository to your system. In CentOS 8, you can add and set up docker’s repository using the DNF software package manager. It helps you in installing new packages and repositories, performs updates, and also helps in removing extra packages on Linux distributions.
So, add and enable the official Docker repository CE using the ‘dnf’ command:
$ sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
The system displays a notification on the terminal window after successfully adding docker’s repository.
Now, you can also see the repository details by using this command:
$ sudo dnf repolist -v
Step 2: Install Docker on CentOS 8
Once the Doker’s repository is added to your system, you can install docker on CentOS 8. The installation process is quite simple and easy. If you want to install the latest docker version from the docker’s repository, use the below command:
$ sudo dnf install docker-ce --nobest --allowerasing -y
The above command will erase the conflicting packages to resolve the dependencies with “–nobest” and “allowerasing” options.
After that, the docker installation will be complete on your system. In a while, you will see a complete message on the terminal, it means docker has been installed on your system but, to use docker first, you need to install the docker daemon service.
Step 3: Enable and install Docker Daemon Service
The docker service automatically starts on your system. but, if it is not running then you can enable and start the docker service using the following commands:
$ sudo systemctl enable docker
$ sudo systemctl start docker
After enabling the docker daemon service, you can verify the running status of this service on your CentOS 8 system by using this command:
$ sudo systemctl status docker
As we can see that docker service is active and running on this system. The same output should display on your terminal window:
Step 4: Test Docker installation by pulling the container image
Docker has a repository where all docker images are stored. This repository is known as “Docker Hub.” You can pull any required docker image from the docker hub. Each docker image contains software along with all application dependencies and libraries. Docker containers can run on the docker platform using these docker images.
Docker hub also allows you to host your docker images on docker hub. After completing the docker installation, you can test its working by pulling a test docker image from a docker hub.
Step 5: Download and run a Docker Image from Docker Hub
Let’s download or pull a ‘Hello World’ docker image from the docker hub and run it on this system by using the following command:
$ sudo docker run hello-world
Similarly, if you want to run other docker images, you can search for them before using them. For example, if you need to install ‘ansible’ for CentOS 7, search it using this command:
$ sudo docker search ansible
The above command will show you all the relevant docker images on the terminal screen.
After installing docker images, you can also list all installed docker images on your system by using this command:
$ sudo docker images
That’s all about the Docker installation and testing.
We learned in this tutorial how to install Docker on CentOS 8 Linux system using a command. Explore how to get or download docker images from the docker hub and run it on a Linux system. I hope you have a better understanding of docker installation. To learn more about docker, you can visit the official docker documentation and user guides.