Installing Docker on CentOS 9 Stream

Docker has become a crucial tool for developers, enabling them to package applications into containers, which are standalone executable packages containing everything needed to run a piece of software, including the code, runtime, libraries, environment variables, and config files. This article will walk you through the process of installing Docker on CentOS 9 Stream, breaking down each step to ensure a smooth and successful installation.

In this tutorial you will learn:

  • How to add the Docker repository to CentOS 9 Stream
  • How to install Docker Engine
  • How to manage Docker as a non-root user
  • How to run a test Docker container
Installing Docker on CentOS 9 Stream
Installing Docker on CentOS 9 Stream
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System CentOS 9 Stream
Software Docker CE (Community Edition)
Other Internet connection, terminal access
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Installing Docker on CentOS 9 Stream

Before diving into the installation process, it’s crucial to understand the importance of Docker and its impact on development workflows. Docker simplifies the process of managing application processes in containers, which are isolated from each other and the host system. This isolation improves the security and efficiency of deploying applications.

  1. Add Docker Repository: Begin by adding the official Docker repository to your CentOS system. This enables you to install the latest version of Docker directly from Docker Inc.
    $ sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
    $ sudo dnf repolist -v

    This step ensures your system recognizes the Docker repository and lists it among its sources, allowing for the installation of Docker packages.

    Added Docker repository
    Added Docker repository
  2. List Docker Versions: Check the available versions of Docker by listing them. This can help you decide if you want to install the latest version or select a specific one.
    $ dnf list docker-ce --showduplicates | sort -r

    This command lists all available versions of Docker CE, sorted in reverse order, making it easier to identify the most recent version.

    List of available Docker packages
    List of available Docker packages
  3. Install Docker CE: Now, install the Docker Engine using the yum package manager. This command installs the latest version of Docker CE.
    $ sudo yum install docker-ce

    After executing this command, Docker will be installed on your system, including all necessary dependencies.

    Install Docker package
    Install Docker package
  4. Enable and Start Docker Service: To ensure Docker starts automatically at boot and is currently running, enable and start the Docker service.
    $ sudo systemctl enable --now docker
    $ sudo systemctl status docker

    This step confirms that the Docker service is enabled and running properly on your system.

    Enable Docker to start after reboot and start the Docker service
    Enable Docker to start after reboot and start the Docker service
  5. Manage Docker as a Non-root User: By default, running Docker requires root privileges. However, you can add your user to the Docker group to manage Docker as a non-root user. Replace ‘linuxconfig’ with your username.
    $ sudo usermod -aG docker $(whoami)
    $ sudo usermod -aG docker linuxconfig



  6. Apply changes:
    After adding your user to the Docker group, log out and log back in or start a new shell to apply the changes.
  7. Run a Test Docker Container: Finally, test your Docker installation by running a Hello World container.
    $ docker run hello-world

    This command downloads a test image and runs it in a container. If the container runs successfully, your Docker installation is working correctly.

    Docker Hello World test
    Docker Hello World test

Conclusion

By following these steps, you have successfully installed Docker on CentOS 9 Stream, added your user to the Docker group to manage Docker without root privileges, and tested your installation by running a Docker container. Docker opens up a world of possibilities for developing, shipping, and running applications efficiently. With Docker installed, you’re now ready to explore the vast ecosystem of Docker containers and develop your own container