How to Install Docker on RedHat/CentOS/Rocky: Is Your Server Ready for Containers?
Installing Docker Step-by-Step — The exact commands you need to install Docker on Redhat-based systems
Hello Everyone, In this article, we will look at how to install Docker on CentOS.
Why Use Docker?
Docker simplifies development and deployment, especially in environments where consistency is crucial. Here’s why Docker is essential:
- Portability: Write code once, run it anywhere. Docker ensures that the application works the same way in development, testing, and production.
- Scalability: Docker containers are lightweight, allowing us to run multiple instances across environments with ease.
- Resource Efficiency: Unlike VMs, Docker containers share the OS kernel, meaning less overhead and faster performance.
- Rapid Deployment: Docker images can be built, tested, and deployed quickly, reducing time-to-market.
For more about Docker ..!
Step 1: Clean the old packages
Initially clean the old docker packages if you have installed the older version of the docker
sudo yum remove -y docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
Step 2: Install Docker Repository
Add the latest docker repository on the Centos machine
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Step 3: Install the Docker packages
Once the repo is added install the latest docker packages
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 4: Configure Docker to start on boot with systemd
Once we installed the packages, enable docker on boot and start the docker service.
On Debian and Ubuntu, the Docker service starts on boot by default. To automatically start Docker and containerd on boot for other Linux distributions using systemd, run the following commands:
sudo systemctl start docker && sudo systemctl enable docker
Step 5: Install Hello World container
Now run the Hello Word ! on Docker to verify Docker is running.
sudo docker run hello-world
Linux post-installation steps for Docker Engine
These optional post-installation procedures describe how to configure your Linux host machine to work better with Docker.
Manage Docker as a non-root user
The Docker daemon binds to a Unix socket, not a TCP port. By default it’s the root
user that owns the Unix socket, and other users can only access it using sudo
. The Docker daemon always runs as the root
user.
Warning:
The
docker
group grants root-level privileges to the user. For details on how this impacts security in your system, see Docker Daemon Attack Surface.To run Docker without root privileges, see Run the Docker daemon as a non-root user (Rootless mode).
To create the docker
group and add your user:
- Create the
docker
group.
sudo groupadd docker && sudo usermod -aG docker $USER
- Log out and log back Again.And Run the below commands.
newgrp docker
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R
docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints a message and exits.
✅✅feel free to connect with us.
LinkedIn: https://www.linkedin.com/in/karthick-dkk/
Follow my Medium Account (To get valuable information)
For more updates: subscribe to this medium account.