Master Docker on Rocky Linux 9: Easy Guide for Linux Enthusiasts!

3 min read 1 month ago
Published on Sep 05, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through the process of mastering Docker on Rocky Linux 9. Docker is a powerful tool that enables developers to create, deploy, and manage applications in containers. This step-by-step guide will help you install Docker, configure it, and start using it effectively on your Rocky Linux system.

Step 1: Install Docker

To get started with Docker, you need to install it on your Rocky Linux 9 system.

  1. Update your system: Open your terminal and run the following command to ensure your package manager is up to date:

    sudo dnf update
    
  2. Install required packages: Install some essential packages needed for Docker installation:

    sudo dnf install -y yum-utils device-mapper-persistent-data lvm2
    
  3. Set up the Docker repository: Add the Docker repository to your system:

    sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    
  4. Install Docker Engine: Now, install Docker using the command:

    sudo dnf install -y docker-ce docker-ce-cli containerd.io
    
  5. Start Docker service: After installation, start the Docker service with:

    sudo systemctl start docker
    
  6. Enable Docker to start on boot: To ensure Docker starts automatically when your system boots, run:

    sudo systemctl enable docker
    

Step 2: Verify Docker Installation

Once Docker is installed, it’s crucial to verify that it is running correctly.

  1. Check Docker status: Use the following command to check if Docker is active:

    sudo systemctl status docker
    
  2. Run a test container: To confirm that Docker is functioning, run a simple container:

    sudo docker run hello-world
    

    This command downloads a test image and runs it in a container. If everything is working, you will see a success message.

Step 3: Manage Docker as a Non-root User

By default, Docker commands need to be run with root privileges. To manage Docker as a non-root user, follow these steps:

  1. Create a Docker group: Add the current user to the Docker group:

    sudo groupadd docker
    sudo usermod -aG docker $USER
    
  2. Log out and back in: To apply the group changes, log out of your session and log back in.

  3. Verify Docker access: Run a Docker command without sudo to ensure proper permissions:

    docker run hello-world
    

Step 4: Pull and Run Docker Containers

With Docker installed and configured, you can start pulling and running containers.

  1. Search for an image: Use the following command to search for available Docker images:

    docker search <image-name>
    
  2. Pull an image: Once you find an image you want, pull it using:

    docker pull <image-name>
    
  3. Run a container: Start a container from the pulled image with:

    docker run -d <image-name>
    

    Replace <image-name> with the name of the image you pulled.

Step 5: Managing Docker Containers

Learn how to manage your running containers effectively.

  1. List running containers: To see all running containers, use:

    docker ps
    
  2. Stop a container: To stop a running container, execute:

    docker stop <container-id>
    
  3. Remove a container: To remove a stopped container, run:

    docker rm <container-id>
    

Conclusion

You have successfully installed Docker on Rocky Linux 9 and learned the basics of running and managing containers. Remember to explore Docker's extensive documentation for advanced features and best practices. Your next steps could include learning about Docker Compose for multi-container applications or diving deeper into Docker networking and orchestration. Happy containerizing!