How to install and configure docker in Rocky Linux/Alma Linux 9

Docker is an open source containerization platform. It enables developers to package applications into containers—standardized executable components combining application source code with the operating system (OS) libraries and dependencies required to run that code in any environment.

Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. 

In this guide we are going to explore various options to install docker in Alma Linux 9.

Also check

Table of Content

  1. Update system packages
  2. Uninstall old versions
  3. Installing docker
  4. Starting and enabling Docker
  5. Uninstalling Docker

Ensure that the system is updated

Before proceeding let’s ensure that our system is up to date. Use this command to update the system and all the packages

sudo dnf -y update

Uninstall old docker versions

If older versions of docker are installed in the system, uninstall them, along with associated dependencies.

sudo dnf remove docker \
    docker-client \
    docker-client-latest \
    docker-common \
    docker-latest \
    docker-latest-logrotate \
    docker-logrotate \
    docker-engine

Installing docker

There are multiple ways of installing docker in Centos 8. You can:

  • Set up docker repositories. This is recommended as you can even upgrade docker once set up
  • Download rpm and install manually
  • You can choose an automated convenience scripts to install Docker

Install using the repository

The docker packages are not found in the default Alma Linux 9 repositories. You need to set up the Docker repository when installing docker in a new system.

Install the yum-utils package (which provides the yum-config-manager utility) and set up the stable repository.

sudo yum install -y yum-utils

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

To install the latest version of Docker Engine and containerd:

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

This command installs Docker, but it doesn’t start Docker. It also creates a docker group, however, it doesn’t add any users to the group by default.

To install a specific version of Docker Engine, list the available versions in the repo, then select and install:

a. List and sort the versions available in your repo. This example sorts results by version number, highest to lowest, and is truncated:

# sudo dnf list docker-ce --showduplicates | sort -r

Installed Packages
docker-ce.x86_64               3:20.10.17-3.el9                docker-ce-stable
docker-ce.x86_64               3:20.10.17-3.el9                @docker-ce-stable
docker-ce.x86_64               3:20.10.16-3.el9                docker-ce-stable
docker-ce.x86_64               3:20.10.15-3.el9                docker-ce-stable

The above command will list packages based on which repositories are enabled.

Install a specific version by its fully qualified package name, which is the package name (docker-ce) plus the version string (2nd column) starting at the first colon (:), up to the first hyphen, separated by a hyphen (-). For example3:20.10.7.

sudo dnf install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

Install using a package

If for any reason you can not use docker’s repository for the installation, you can download an rpm package and install manually.

Go to https://download.docker.com/linux/centos/ and choose your version of CentOS. Then browse to x86_64/stable/Packages/ and download the .rpm file for the Docker version you want to install

Install Docker Engine, changing the path below to the path where you downloaded the Docker package.

sudo yum install /path/to/package.rpm

Docker is installed but not started. The docker group is created, but no users are added to the group.

Install using the convenience script

Docker provides a convenience script at get.docker.com to install Docker into development environments quickly and non-interactively. The convenience script is not recommended for production environments, but can be used as an example to create a provisioning script that is tailored to your needs. 

The script requires root or sudo privileges to run. The script attempts to detect your Linux distribution and version and configure your package management system for you, and does not allow you to customize most installation parameters. The script installs dependencies and recommendations without asking for confirmation. By default, the script installs the latest stable release of Docker, containerd, and runc.

You can run the script with the DRY_RUN=1 option to learn what steps the script will execute during installation:

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ DRY_RUN=1 sh ./get-docker.sh

This downloads the script from get.docker.com and runs it to install the latest stable release of Docker on Linux:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Starting and enabling docker

On RPM based distributions, such as CentOS, Fedora, RHEL or SLES, you need to start it manually using the appropriate systemctl or service command. Non-root users cannot run Docker commands by default.

Use this command to start docker

sudo systemctl start docker

Confirm that docker is running by issuing the status command

$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
     Active: active (running) since Fri 2022-08-19 10:16:07 UTC; 9s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 116126 (dockerd)
      Tasks: 7
     Memory: 30.6M
        CPU: 247ms
     CGroup: /system.slice/docker.service
             └─116126 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Aug 19 10:16:06 localhost.localdomain dockerd[116126]: time="2022-08-19T10:16:06.945372165Z" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:/>
Aug 19 10:16:06 localhost.localdomain dockerd[116126]: time="2022-08-19T10:16:06.945407166Z" level=info msg="ClientConn switching balancer to \"pick_first\"" m>
Aug 19 10:16:06 localhost.localdomain dockerd[116126]: time="2022-08-19T10:16:06.970797404Z" level=error msg="Failed to built-in GetDriver graph btrfs /var/lib>
Aug 19 10:16:06 localhost.localdomain dockerd[116126]: time="2022-08-19T10:16:06.986082868Z" level=info msg="Loading containers: start."
Aug 19 10:16:07 localhost.localdomain dockerd[116126]: time="2022-08-19T10:16:07.109918570Z" level=info msg="Default bridge (docker0) is assigned with an IP ad>
Aug 19 10:16:07 localhost.localdomain dockerd[116126]: time="2022-08-19T10:16:07.228405219Z" level=info msg="Loading containers: done."
Aug 19 10:16:07 localhost.localdomain dockerd[116126]: time="2022-08-19T10:16:07.305824306Z" level=info msg="Docker daemon" commit=a89b842 graphdriver(s)=overl>
Aug 19 10:16:07 localhost.localdomain dockerd[116126]: time="2022-08-19T10:16:07.306123014Z" level=info msg="Daemon has completed initialization"
Aug 19 10:16:07 localhost.localdomain systemd[1]: Started Docker Application Container Engine.

To enable docker on boot, use this command:

sudo systemctl enable docker

Docker will not work for no-root users or without sudo, you will get the error below if you attempt.

$ docker ps
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied

To use docker without Sudo, add the current user to the docker group then re-login.

Add the user to the docker group:

$ sudo usermod -aG docker ${USER}

Then relogin as the user

$ sudo su - ${USER}

Then check that you are now part of docker

$ id
uid=1000(centos) gid=1000(centos) groups=1000(centos),4(adm),190(systemd-journal),985(docker) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

Now we can confirm that everything is working by issuing the docker run command for the hello-world image:

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

Uninstalling Docker

If you no longer need docker in the system, use these commands to uninstall it

sudo dnf remove docker-ce docker-ce-cli containerd.io
  1. Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

You must delete any edited configuration files manually.

Conclusion

We have managed to install docker on a centos system either using the repository or downloading an rpm then installing it or using a convenience script.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy