Get 50% Discount Offer 26 Days

Recommended Services
Supported Scripts
WordPress
Hubspot
Joomla
Drupal
Wix
Shopify
Magento
Typeo3
How to Install Docker on CentOS Stream 9?

What Is Docker? Why Should We Install Docker on CentOS Stream?

This guide provides complete instructions to install Docker on CentOS Stream. Docker is a powerful tool for containerizing applications, allowing developers to package their code and dependencies in a single

Table of Contents

If you still need to get Docker installed on CentOS Stream 9, you’re in the right place. In this guide, you’re going to learn how to set up repositories, configure Docker, and deal with common problems in the process.

Section 1: Requirements for Installing Docker on CentOS Stream 9

If you still need to set up your CentOS Stream 9 system before installing Docker, you need to do that first.

Step 1: Check System Requirements

Docker requires a 64-bit CentOS system. As a minimum, 2 GB RAM is enough, though 4 GB RAM is highly recommended if you’re planning to run many containers.

Step 2: User Permissions

Make sure that you have root or sudo privileges on the system, as installing and managing Docker requires administrative permissions.

Step 3: Update System Packages

To avoid conflicts while setting up Docker, we first update all available packages to their latest.

sudo dnf update -y
Terminal output showing system package updates using the sudo dnf update -y command on Linux

Step 4: Install Required Utilities

Install the dnf-plugins-core package to enable additional DNF features for managing repositories:

sudo dnf install -y dnf-plugins-core
Terminal output showing installation of the dnf-plugins-core package on Linux using the sudo dnf install command

With these prerequisites met, you’re ready to install Docker on CentOS Stream 9.

Section 2: Installing Docker on CentOS Stream 9 from the Official Docker Repository

Installing Docker on CentOS Stream, the official Docker repository, would be the best source because that assures that you are getting the latest and most compatible Docker versions.

Step 1: Add the Docker Repository

To begin, add the official Docker repository to your system’s sources. It will allow your package manager to pull Docker CE (Community Edition) and its dependencies directly from the trusted source of Docker and then install them on your machine:

sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

This command configures DNF to recognize Docker’s repository, making future Docker installations and updates.

Terminal output showing the addition of the Docker repository to Docker on CentOS Stream

Step 2: Install Docker

Once the repository is configured, proceed to install Docker CE along with important components like Docker CLI and containerd. Execute the following command:

sudo dnf install docker-ce docker-ce-cli containerd.io -y

The -y flag makes sure the installation proceeds without needing user confirmation, saving time. This step is for featuring the core functionality of Docker on your CentOS System, aka containers management and creation.

Installing Docker CE, Docker CLI, and containerd.io on CentOS.

Step 3: Start Docker

After installation, start the Docker service using systemctl:

sudo systemctl start docker

The Docker daemon is started, and containerized applications are able to run when Docker is started. After this step, it’s a good idea to check Docker runs easily.

Starting Docker service using sudo systemctl start docker command

Step 4: Enable Docker on Startup

To make sure Docker starts automatically after a system reboot, enable the Docker service:

sudo systemctl enable docker

It’s especially useful for production, which requires consistent availability. With this command, the Docker would start by itself whenever you reboot the computer, So it means you will no longer have to start Docker manually.

Enabling Docker to start automatically on system boot with sudo systemctl enable docker

Step 5: Verify Docker Installation

Check that Docker has been installed successfully by displaying its version:

sudo docker --version
Verifying Docker installation by displaying its version using docker --version

If no errors appear, this command displays Docker’s version number and is successful if it displays. Additionally, you can also run sudo docker and hello-world to see if the Docker works by running just a simple container.

Section 3: Alternative Method: Installing Docker Using CentOS Stream Extras Repository

You can set up Docker through the repository of Docker’s official repository if you do not want to add it to Docker’s repository. It offers us an alternative that is another Docker source, and it can work for us on CentOS Stream.

Step 1: Enable the CentOS Stream Extras Repository

The CentOS Stream Extras repository may already be enabled, but if not, install it with:

sudo dnf config-manager --set-enabled crb

The crb (CodeReady Builder) repository contains additional packages needed for building and deploying applications on CentOS Stream.

Enabling CentOS Stream Extras repository using sudo dnf config-manager --set-enabled crb

Step 2: Install Docker from CentOS Stream Extras

Install Docker using the CentOS Extras repository:

sudo dnf install -y docker

With -y automatically does the installation, so it’s easier. This command will install Docker CE the way it’s meant to be used, making your system all set for all container operations.

Step 3: Start Docker

After installation, activate Docker:

sudo systemctl start docker

For running a container and using Docker’s feature, it is important to start the Docker. Check that Docker is running OK.

Starting Docker service using sudo systemctl start docker command.

Step 4: Enable Docker to Start on the Boot

Set Docker to start automatically on system boot:

sudo systemctl enable docker

This process is a critical step for continuous availability environments, this command tells Docker also to start up when you reboot.

Enabling Docker to start automatically at boot using sudo systemctl enable docker

Step 5: Verify Installation

Run a test Docker container to confirm successful installation:

sudo docker run hello-world

For additional verification, run a test container using sudo docker and run hello-world to confirm Docker is fully functional. This process confirms that Docker can pull and run images without issues.

Running a test Docker container using sudo docker run hello-world to verify installation

If you see the message from the hello-world container, Docker is working correctly.

Section 4: Post-Installation Steps for Docker on CentOS Stream 9

This process is a critical step for continuous availability environments, this command tells Docker also to start up when you reboot.

Step 1: Add User to Docker Group

To allow non-root users to run Docker without the sudo command, add your user to the Docker group.

sudo usermod -aG docker $USER
Adding a user to the Docker group with sudo usermod -aG docker $USER

Log out and back in for the new permissions to take effect.

Step 2: Enable Docker to Start on the Boot

Make sure Docker is configured to start on boot:

sudo systemctl enable docker

Enabling Docker to start automatically on boot using sudo systemctl enable docker

Step 3: Test Docker Without sudo

Verify Docker works without requiring sudo by running:

docker run hello-world

If the hello-world message displays, Docker is set up correctly for non-root access.

Testing Docker functionality without sudo by running docker run hello-world

Section 5: Configuring Docker Storage on CentOS Stream 9

Docker’s storage configuration can be customized to improve performance or manage storage on different disks.

Step 1: View Default Storage Location

Docker stores data by default in 

/var/lib/docker
Viewing Docker's default storage location at /var/lib/docker and its contents.

Step 2: Change Storage Driver (Optional)

The overlay2 storage driver is recommended for performance. To confirm or configure it, add it to Docker’s daemon configuration file.

Step 3: Modify Docker Storage Path

To change Docker’s storage path, open or create the Docker daemon configuration file:

sudo nano /etc/docker/daemon.json

Add the following configuration:

{
  "data-root": "/new/docker/path"
}
Editing Docker's daemon configuration file to change storage path with sudo nano /etc/docker/daemon.json

Replace /new/docker/path with your preferred storage path.

Step 4: Restart Docker

To apply the changes, restart Docker:

sudo systemctl restart docker
Restarting Docker service using sudo systemctl restart docker to apply changes

Section 6: Configuring the Docker Daemon on CentOS Stream 9

The Docker daemon can be configured to suit different requirements.

Step 1: Open Daemon Configuration File

Edit the Docker daemon configuration file:

sudo nano /etc/docker/daemon.json

Step 2: Configure Insecure Registries

To pull images from private or local registries, add them to the daemon file:

{
  "insecure-registries": ["your_registry_domain.com:5000"]
}
Configuring Docker to use insecure registries by adding them to the daemon file.

Step 3: Set Up Docker Logging Options

Set up logging options to limit log sizes and improve performance:

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}
configuring Docker's logging driver and log options.

Step 4: Restart Docker Daemon

Apply your changes by restarting Docker:

sudo systemctl restart docker
Step to restart Docker daemon after applying configuration changes

Section 7: Managing Docker Containers and Images on CentOS Stream 9

Here are some key Docker commands for managing containers and images.

Step 1: Pulling Docker Images

Pull an image from Docker Hub:

sudo docker pull nginx
Step showing the process of pulling a Docker image (nginx) from Docker Hub

Step 2: Running a Docker Container

Run a container in detached mode:

sudo docker run -d --name my-nginx -p 80:80 nginx
Step showing how to run a Docker container in detached mode with a specified name and port mapping

Step 3: Listing Containers and Images

To view active containers and available images:

sudo docker ps
Command to view active Docker containers and available images along with their status and details.
sudo docker images
Command to list Docker images along with their repository, tag, image ID, creation date, and size

Step 4: Stopping and Removing Containers

Stop and remove containers when they’re no longer needed:

sudo docker stop my-nginx
Command to stop a Docker container named 'my-nginx
sudo docker rm my-nginx
Command to remove a Docker container named 'my-nginx

Section 8: Updating and Uninstalling Docker on CentOS Stream 9

Follow these steps to update or uninstall Docker on CentOS Stream 9.

Step 1: Updating Docker

Update Docker to the latest version:

sudo dnf check-update
Command to check for available updates for Docker using the dnf package manager
sudo dnf update docker-ce docker-ce-cli containerd.io
Command to update Docker to the latest version using dnf package manager

Step 2: Uninstalling Docker

If you need to remove Docker:

sudo dnf remove docker-ce docker-ce-cli containerd.io
Command used to remove Docker and its related packages along with unused dependencies
sudo rm -rf /var/lib/docker
Command used to remove Docker's stored data in the /var/lib/docker directory

Section 9: Troubleshooting Common Docker Installation Issues on CentOS Stream 9

Here are solutions to common Docker installation issues.

Issue: Docker Daemon Fails to Start

Check Docker logs for more details:

sudo journalctl -u docker
Checking Docker daemon logs for troubleshooting when Docker fails to start

Issue: Cannot Connect to Docker Daemon

Make sure Docker is running and check permissions:

sudo systemctl start docker
Starting Docker to resolve connection issues with the Docker Daemon
sudo systemctl enable docker
Enabling Docker to start automatically on system boot

Issue: Firewall Blocks Docker Ports

Make sure Docker’s ports are open by configuring the firewall:

sudo firewall-cmd --zone=public --add-masquerade --permanent
Configuring the firewall to allow Docker's ports for network communication
sudo firewall-cmd --reload
Reloading the firewall to apply the new configuration settings for Docker

Network Connectivity Issues

If containers experience network problems, reset Docker network settings:

sudo systemctl restart docker
Restarting Docker service to resolve any network-related issues with containers

Section 10: Frequently Asked Questions (FAQ) on Docker Installation

1. Can I install Docker on other CentOS versions?

Yes, Docker can also be installed on CentOS 8, CentOS 7, and newer versions of CentOS Stream.

2. How do I set up a private Docker registry?

You can run the registry Docker image to set up a private registry and configure Docker’s daemon to recognize it.

3. What’s the difference between Docker CE and Docker EE?

Docker CE is free and open-source, while Docker EE (Enterprise Edition) includes additional features and support.

Conclusion

Congrats, you’ve already installed Docker on CentOS Stream 9, and got it running in top shape. Docker makes it possible to bring the app code, dependencies, and environment into containers and keep everything consistent across environments. Now you are ready to dive into Docker’s more complex features, which include such as docker-compose and container orchestration.

About the writer

Vinayak Baranwal Article Author

This article was written by Vinayak Baranwal, For more insightful content or collaboration opportunities, feel free to connect with Vinayak on LinkedIn through the provided link.

Leave a Reply

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

Lifetime Solutions:

VPS SSD

Lifetime Hosting

Lifetime Dedicated Servers