Install Docker & Docker-Compose on Rocky Linux

Install Docker & Docker-Compose on Rocky Linux

Update packages and Install updates

Login to Rocky Linux and install all the available updates and then reboot the system once.

sudo dnf update -y 
reboot

Install Docker and Docker Compose using automated Script

If you wish to go with the short path, Please use below bash script to install docker and docker-compose on Rocky linux.

nano docker.sh

paste below code

#!/usr/bin/env bash 

## Script to install docker-ce on Rocky Linux
## Run using `sudo rocky-docker.sh`

# Ensuring "GROUP" variable has not been set elsewhere
unset GROUP

echo "Removing podman and installing Docker CE"
dnf remove -y podman buildah
dnf install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

echo "Setting up docker service"
systemctl enable docker
systemctl start docker
systemctl status docker

echo "Adding permissions to current user for docker, attempting to reload group membership"
usermod -aG docker -a $USER
GROUP=$(id -g)
newgrp docker
newgrp $GROUP
unset GROUP

echo "Install completed, though you will probably require logout/login if the following command fails:"
docker ps

Save the script with Control+X hit Y, change the script to executable

chmod +x docker.sh

run the script with sudo

sudo sh docker.sh

The code is available in Github Repo : Rockydocker

Now, let's see the hard way ;)

Configure Docker Package Repository & Install Docker

To install latest and stable version of docker, configure its official package repository using the following command,

Set up the repository

 sudo yum install -y yum-utils
 sudo yum-config-manager \
    --add-repo \
 https://download.docker.com/linux/centos/docker-ce.repo

Install Docker Engine

Install the latest version of Docker Engine, containered, and Docker Compose or go to the next step to install a specific version:

sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

Output of commands would like below:

Docker-Install-dnf-command-rocky-linux

Note: In case you are getting container.io error while installing docker-ce package then run following command,

sudo dnf install docker-ce --allowerasing -y

Start and enable docker Service

Once docker is installed then start and enable its service using following systemctl commands,

sudo systemctl start docker $ sudo systemctl enable docker

Verify that Docker Engine is installed correctly by running the hello-world image.

sudo docker run hello-world

Output,

Test-Docker-Installation-Rocky-Linux

Add user to docker group

in order to run docker command without sudo, you need to add username to docker group

sudo usermod -aG docker $USER

After executing the above command, log out and log in once so that docker group is associated to user and user can run docker commands without sudo.

Install Docker-Compose

Docker Compose command allows to spin up multiple containers in one go. So, to install it run the following commands one after the another.

In order to get the latest release, take the lead of the Docker docs and install Docker Compose from the binary in Docker’s GitHub repository.

Check the current release and if necessary, update it in the command below:

sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Next, set the permissions to make the binary executable:

sudo chmod +x /usr/local/bin/docker-compose

Then, verify that the installation was successful by checking the version:

docker-compose --version

This will print out the version you installed:

docker-compose version 1.23.2, build 1110ad01