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
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
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
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.
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.
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.
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.
Step 5: Verify Docker Installation
Check that Docker has been installed successfully by displaying its version:
sudo 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.
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.
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.
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.
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
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
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.
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
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"
}
Replace /new/docker/path with your preferred storage path.
Step 4: Restart Docker
To apply the changes, restart Docker:
sudo systemctl restart docker
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"]
}
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"
}
}
Step 4: Restart Docker Daemon
Apply your changes by restarting Docker:
sudo systemctl restart docker
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 2: Running a Docker Container
Run a container in detached mode:
sudo docker run -d --name my-nginx -p 80:80 nginx
Step 3: Listing Containers and Images
To view active containers and available images:
sudo docker ps
sudo docker images
Step 4: Stopping and Removing Containers
Stop and remove containers when they’re no longer needed:
sudo docker stop my-nginx
sudo docker rm 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
sudo dnf update docker-ce docker-ce-cli containerd.io
Step 2: Uninstalling Docker
If you need to remove Docker:
sudo dnf remove docker-ce docker-ce-cli containerd.io
sudo rm -rf /var/lib/docker
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
Issue: Cannot Connect to Docker Daemon
Make sure Docker is running and check permissions:
sudo systemctl start docker
sudo systemctl enable docker
Issue: Firewall Blocks Docker Ports
Make sure Docker’s ports are open by configuring the firewall:
sudo firewall-cmd --zone=public --add-masquerade --permanent
sudo firewall-cmd --reload
Network Connectivity Issues
If containers experience network problems, reset Docker network settings:
sudo systemctl restart docker
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
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.