Introduction:
Docker is a popular open-source platform that allows you to automate the deployment and management of applications using containerization. It provides a lightweight and efficient environment to package and run applications consistently across different systems. In this article, we will walk you through the process of installing Docker on Rocky Linux 9 and demonstrate how to use it to run and manage containers effectively.
Step 1: Update System Packages:
Before installing any new software, it is important to update the system packages to their latest versions. Open a terminal on your Rocky Linux 9 server and execute the following command:
sudo dnf update
This command will update the package repositories and ensure that your server has the most recent package information.
Step 2: Install Docker:
Rocky Linux 9 provides the Docker package in its default repositories, making the installation process straightforward. Run the following command to install Docker:
sudo dnf install docker
This command will install the Docker engine and its dependencies.
Step 3: Start and Enable Docker:
After the installation is complete, start the Docker service using the following command:
sudo systemctl start docker
To ensure that Docker starts automatically on system boot, enable the service by running:
sudo systemctl enable docker
Step 4: Verify Docker Installation:
To verify that Docker is installed and running correctly, you can check its status using the following command:
sudo systemctl status docker
If Docker is active and running, you should see a “active (running)” status.
Step 5: Run Your First Docker Container:
Now that Docker is installed, you can run your first container. Let’s start with a simple example of running an official Nginx web server container. Run the following command:
sudo docker run -d -p 80:80 nginx
This command pulls the Nginx image from the Docker Hub, creates a container based on that image, and maps port 80 on your host to port 80 inside the container.
Step 6: Access the Container:
Once the container is running, you can access the Nginx web server by opening a web browser and navigating to http://localhost. You should see the default Nginx welcome page.
Step 7: Managing Docker Containers:
Docker provides a set of commands to manage containers. Here are some useful commands to get you started:
docker ps
: Lists all running containers.docker stop <container_id>
: Stops a running container.docker start <container_id>
: Starts a stopped container.docker rm <container_id>
: Removes a container.docker images
: Lists all available Docker images.docker rmi <image_id>
: Removes an image.
Conclusion:
Congratulations! You have successfully installed Docker on Rocky Linux 9 and learned how to run and manage containers. Docker allows you to package and deploy applications quickly and efficiently, providing flexibility and scalability to your infrastructure. Explore more about Docker and its capabilities to leverage the power of containerization in your projects. Remember to follow best practices for container security and management, such as regularly updating your Docker images and securing sensitive data within containers. Happy containerizing!