Docker is a popular platform for developing, shipping, and running applications in containers. Below are the steps to install Docker on CentOS / Rocky Linux.
Prerequisites
- A CentOS 8 system with root or sudo privileges.
- A stable internet connection.
- Terminal access.
Step 1: Update the System
Before installing Docker, ensure your system is up to date.
sudo dnf update -y
Step 2: Add the Docker Repository
Docker is not available in the default CentOS 8 repositories, so you need to add the official Docker repository.
- Install the dnf-plugins-core package to manage repositories:
sudo dnf install -y dnf-plugins-core
- Add the Docker repository:
sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
Step 3: Install Docker
- Install Docker Engine (Community Edition) and its dependencies:
sudo dnf install docker-ce docker-ce-cli containerd.io -y
- Verify the installation by checking the Docker version:
docker --version
You should see output like: Docker version 20.10.x, build xxxxxxx.
Step 4: Start and Enable Docker
- Start the Docker service:
sudo systemctl start docker
- Enable Docker to start on boot:
sudo systemctl enable docker
- Check the status of the Docker service:
sudo systemctl status docker
You should see active (running) in the output.
Step 5: Verify Docker Installation
- Run a test container to ensure Docker is working:
sudo docker run hello-world
If Docker is installed correctly, you’ll see a message like:
Hello from Docker! This message shows that your installation appears to be working correctly.
Manage Docker as a Non-Root User (Optional)
By default, Docker requires root privileges. To run Docker commands without sudo, add your user to the docker group:
- Add your user to the docker group:
sudo usermod -aG docker $USER
- Log out and log back in for the changes to take effect.
- Verify that you can run Docker commands without sudo:
docker run hello-world
Uninstall Docker (Optional)
If you ever need to uninstall Docker, use the following commands:
- Remove Docker packages:
sudo dnf remove docker-ce docker-ce-cli containerd.io
- Delete Docker images, containers, and volumes:
sudo rm -rf /var/lib/docker
You’ve successfully installed Docker on CentOS 8! You can now start using Docker to deploy and manage containers. For more advanced configurations, refer to the official Docker documentation.
A big thank you for exploring TechsBucket! Your visit means a lot to us, and we’re grateful for your time on our platform. If you have any feedback or suggestions, we’d love to hear them.