Docker. This is a buzzword that you might probably have come across in various forums and often gets a mention, especially in the virtualization circles. So what is Docker and why is it so damn popular in the IT industry? Docker is a containerization platform that enables developers to easily develop, test and deploy their applications on containers. Also, it is completely free to download and install. Docker Containers are isolated environments completely independent from the host OS, that ship with libraries and dependencies that are needed by the applications to run. In so doing, containers ensure that applications will run on any Linux system without a hitch resulting from differences is the OS version or various other settings. In this guide, you will learn how to install Docker on CentOS 8.
How does Docker differ from Virtualization?
The two technologies are similar in some sense, but unlike a VM (virtual machine), Docker does not create an entire operating system atop of the host system. It rides on the same Linux kernel as the host system and runs containerized applications while still leveraging on the same kernel. This results in boosted application performance and resource optimization.
Docker is a darling of Linux systems such as RedHat and Ubuntu and is mostly used by developers and system administrators in deploying applications. It has largely been embraced by corporate enterprises such as Oracle and expanded to cloud platforms such as AWS and Microsoft Azure. You can easily deploy a LAMP stack using Docker and other applications such as WordPress using Docker compose. Since it’s initial release in 2013, It is estimated that approximately 3.7 million containers have been dockerized and close to 37 billion have been downloaded to date.
Given the brief overview of Docker, let’s now get our hands dirty and proceed to install and configure Docker on CentOS 8.
As you get started, ensure that the following requirements have been fulfilled:
An instance of CentOS 8 with a sudo user.
A stable internet connection.
Step 1: Enable the Docker CE repository
Docker packages are no longer available in CentOS 8 repositories. Therefore, we need to first enable the Docker CE repository by invoking the command below:
$ dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
Once enabled, you can now proceed to verify which Docker versions are available for download from the repository. To achieve this, execute the command:
$ sudo dnf list docker-ce
This returns a list of Docker versions as shown below:
Step 2: Install Docker on CentOS 8
Having had a glimpse of the available Docker versions, You can install Docker on CentOS 8 by running the command below. This installs the latest version of Docker.
$ sudo dnf install docker-ce --nobest -y
This is going to install Docker alongside its dependencies such as docker-ce command-line tool.
Upon completion of the installation, start Docker and enable it upon booting by invoking the following commands:
$ sudo systemctl start docker $ sudo systemctl enable docker
To verify the everything is working as expected, confirm Docker status a shown:
$ sudo systemctl status docker
If you are curious as to what version you are running, run:
$ docker --version
Alternatively, you can use the following rpm command to retrieve finer details such as version, release, architecture, and install data and so much more.
$ rpm -qi docker-ce
Perfect! Up until this point, we have managed to successfully install Docker on our CentOS 8 system. In the next step, we will look at how you can run docker using a few commands.
Step 3: Run Docker on CentOS 8
To run docker commands as the regular user, we must first add that user to the docker group. To achieve this, run the following
command as the root user.
$ usermod -aG sudo username
In our case, the username is unixmen, and therefore the command translates to:
$ usermod -aG sudo unixmen
To verify that everything is working just fine, we are going to pull a “hello-world“ image from Docker hub and run the container locally on our system. To do this, run the command:
$ docker run hello-world
You should get the output shown below with the message “Hello from Docker!”
Step 4: Basic Docker commands
Having successfully installed Docker, let’s have a look at a few commands to get you started out.
To pull an image from Docker hub without running it, use the syntax:
$ docker pull image-name
For example, to pull a Ubuntu image from Docker, run:
$ docker pull ubuntu
This will pull a Ubuntu image and save it locally.
To check the images residing on your machine, run the command:
$ docker images
The output indicates that we have 2 images: the Ubuntu image that we have just pulled from Docker and the ‘hello-world’ that we pulled earlier when testing if docker was functioning as expected. The output also prints out additional information such as tags, image ID, date of creation and image size on the last column.
Let’s get more ambitious. We are going to spawn a container from the Ubuntu image and interact with the container. To do so we will run the command:
$ docker run -it ubuntu bash
Once logged in, you can run commands, for example, we are going to verify the version of the image using the command
The output confirms that we are running a Ubuntu 20.04 LTS container! To display running containers run:
$ docker ps
To reveal both stopped and running containers run:
$ docker ps -a
Those are just but a few examples of interacting with a Docker image. Visit the official Docker documentation to get a glance of additional CLI commands.
This wraps up our guide today on how to install Docker on CentOS 8.