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:
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:
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:
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:
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:
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:
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:
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:
- “-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:
In the above output, two Docker containers can be seen i.e., “nginxCont” and “trusting_babbage”.
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.