Docker

How to Install and Use Docker on Fedora and CentOS?

Docker is a containerization forum that allows users to build and manage various types of applications in containers. Fedora and CentOS both are Linux-based operating systems and are utilized as the host operating system for running Docker containers. Docker offers a variety of services and tools to build and deploy applications in containers on these platforms quickly. Moreover, Docker commands are the same for both platforms.

This write-up will illustrate the following:

How to Install Docker on Fedora or CentOS?

To install Docker on Fedora or CentOS, try out the given-provided steps:

  • Update package databases.
  • Add Docker Repository and download Docker using the “curl -fsSL https://get.docker.com/ | sh” script.
  • Start Docker services via the “sudo systemctl start docker” command.
  • Execute Docker commands for verification.

Step 1: Update Package Database

First, execute the below-listed command to check for available updates for the installed packages on the system and update them:

sudo yum check-update

The output shows that the package list is successfully updated.

Step 2: Add Docker Repository and Download Docker

Then, add the official Docker repository to the system’s package sources and install/download Docker’s latest version. After that, install the Docker engine package through the provided command:

curl -fsSL https://get.docker.com/ | sh

The above-executed command has downloaded and installed the latest version of Docker.

Step 3: Start Docker Daemon

Next, type out the given-provided command to start the Docker daemon:

sudo systemctl start docker

This command has started the Docker services.

Step 4: Verify the Status of Services

To verify whether the Docker daemon services have been starting or not by checking its status:

sudo systemctl status docker

It can be seen that the Docker Daemon is running.

Step 5: Verification

Finally, run any Docker command to ensure that the Docker has been installed successfully and its services are running. For instance, execute the below-listed command:

sudo docker run hello-world

The output shows that Docker has been successfully installed on CentOS.

How to Use Docker on Fedora or CentOS?

Docker can be used in different ways on CentOS or Fedora, such as:

  • Pull Image from Docker Hub
  • List All Docker Images
  • Build and Run Docker Container
  • View All Docker Containers

Step 1: Pull an Image from Docker Hub

To pull a particular Docker image from the Docker hub, utilize the “sudo docker pull <image-name>” command:

sudo docker pull nginx:latest

According to the above output, the latest version of the “nginx” image has been downloaded successfully.

Step 2: List All Docker Images

Execute the given-provided command to display all the available Docker images:

sudo docker images

The above output indicates that there are three Docker images available on the local system.

Step 3: Build and Run Docker Container

In order to create and execute a Docker container from a particular Docker image, write out the “sudo docker run -d –name <container-name> <image-name>” command:

sudo docker run -d --name nginxCont nginx:latest

Here:

  • -d” option is utilized to execute the container in the detached mode.
  • –name” defines the container name i.e., “nginxCont”.
  • nginx:latest” is the latest version of the Docker Hub image to utilize for the container:

This command has built and executed the container.

Step 4: View All Docker Containers

Type out the following command to display all the Docker containers:

sudo docker ps -a

In the above output, two Docker containers can be seen i.e., “nginxCont” and “trusting_babbage”.

Conclusion

To install Docker on Fedora or CentOS, first, update package databases. Then, add Docker Repository and download Docker through the “curl -fsSL https://get.docker.com/ | sh” command. Next, start Docker services via the “sudo systemctl start docker” command and verify its status. The user can use Docker on Fedora or CentOS to perform various operations, such as pulling an image from Docker Hub, listing all Docker images, building, and running Docker containers, viewing all containers, and many more.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.