Linux Tactic

Streamlining Container Management: A Guide to Installing and Verifying Docker on CentOS

Docker is a popular platform that lets software developers build, deploy, and run applications in containers. It is a very useful tool for developers who want to separate their applications from the underlying infrastructure and run them in an isolated environment.

CentOS, on the other hand, is a popular Linux distribution that is known for its stability and security. It is widely used for web hosting, database hosting, and other purposes.

In this article, we will discuss how to install Docker on CentOS and update CentOS to ensure that your system is secure and up-to-date.

Installing Docker on CentOS

To install Docker on CentOS, we need to add the official repository, install Docker CE, and set up Docker on CentOS. Let’s discuss each of these steps in detail.

Adding official repository

The first step is to add the official repository for Docker. We can do this by running the following command:

“`

sudo dnf config-manager –add-repo=https://download.docker.com/linux/centos/docker-ce.repo

“`

This command adds the Docker repository to the list of repositories that CentOS uses to search for software packages.

Installing Docker CE

Next, we need to install Docker CE (Community Edition). We can do this by running the following command:

“`

sudo dnf install docker-ce –nobest

“`

This command downloads and installs Docker CE along with its dependencies. We use the –nobest option to prevent dnf (Dandified Yum) from downloading newer packages that may not be compatible with our system.

Setting up Docker on CentOS

Now that we have installed Docker CE, we need to set it up on CentOS. The first step is to add our user to the docker group so that we can use Docker without using sudo.

We can do this by running the following command:

“`

sudo usermod -aG docker $USER

“`

This command adds our user to the docker group. Next, we need to start the Docker daemon and enable it to start automatically at system boot.

We can do this by running the following commands:

“`

sudo systemctl start docker

sudo systemctl enable docker

“`

These commands start the Docker daemon and enable it to start automatically on system boot.

Verifying Docker installation

Now that we have installed and set up Docker on CentOS, we can verify it by running a few commands. Let’s discuss these commands in detail.

First, we can test Docker installation by running a simple hello-world container. We can do this by running the following command:

“`

docker run hello-world

“`

This command should output a message that says “Hello from Docker!”. Next, we can test Docker installation by running a simple Nginx server container.

We can do this by running the following command:

“`

docker run -d –name my-nginx -p 80:80 nginx

“`

This command downloads and runs the Nginx server container and maps port 80 on the container to port 80 on the host. We can then access the Nginx server by navigating to the IP address or hostname of our CentOS server on port 80.

Updating CentOS

To keep our CentOS server secure and up-to-date, we need to regularly update it. We can do this by running the following commands:

“`

sudo dnf update

“`

This command updates all the packages on our CentOS server to the latest version. We should run this command regularly to keep our system secure and up-to-date.

Conclusion

In this article, we discussed how to install Docker on CentOS and update CentOS to keep it secure and up-to-date. By following these steps, we can ensure that our system is running the latest software and is protected against any security vulnerabilities.

3) Adding Docker’s official repository in CentOS

One of the first steps in installing Docker on CentOS is to add the official repository from Docker. A repository is a central location for storing software packages that can be easily downloaded and installed on a CentOS system.

To add the Docker repository, we need to follow the steps below. Step 1: Update the system

Before adding the Docker repository, it is recommended to update the CentOS system to ensure that we have the latest software packages installed.

This can be done by running the following command:

“`

$

sudo dnf update

“`

This command checks for any available software updates and upgrades the system to the latest version if there are any available. Step 2: Install required dependencies

Next, we need to ensure that we have the required dependencies installed on the system.

These dependencies include the dnf-plugins-core utility which is used to manage the repositories. To install the utility, run the command:

“`

$ sudo dnf install -y dnf-plugins-core

“`

Step 3: Add the Docker repository

Now that we have updated the system and installed the required dependencies, we can add the Docker repository.

To do this, we need to run the following command:

“`

$ sudo dnf config-manager –add-repo https://download.docker.com/linux/centos/docker-ce.repo

“`

This command adds the Docker repository to the CentOS system. We can now proceed to install Docker CE.

4)

Installing Docker CE on CentOS

Docker CE (Community Edition) is the most popular version of Docker, designed for use on personal computers and small development teams. To install Docker CE on CentOS, we need to follow the steps below.

Step 1: Install required dependencies

Before installing Docker CE, we need to ensure that we have the required dependencies installed on the system. These dependencies include the containerd.io and docker-ce-cli utilities.

To install the utilities, run the command:

“`

$ sudo dnf install -y containerd.io docker-ce-cli

“`

Step 2: Install Docker CE

Now that we have installed the required dependencies, we can proceed to install Docker CE. To do this, run the command:

“`

$ sudo dnf install -y docker-ce –nobest

“`

This command installs the latest version of Docker CE from the official Docker repository.

The –nobest option ensures that only compatible versions of Docker and its dependencies are installed. Step 3: Start and enable Docker daemon

After installing Docker CE, we need to start the Docker daemon and enable it to run automatically on system boot.

To do this, run the following commands:

“`

$ sudo systemctl start docker

$ sudo systemctl enable docker

“`

This command starts the Docker daemon and enables it to start automatically when the system boots. Step 4: Verify Docker installation

Once we have installed Docker CE, we can verify the installation by running the following command:

“`

$ docker version

“`

This command displays the version of Docker installed on the system, along with the build information and other details.

The output should indicate that Docker is installed and running correctly.

Conclusion

In this article, we discussed how to add the official Docker repository in CentOS and how to install Docker CE on CentOS. With these steps, we can easily set up Docker on our CentOS system and start using it to manage containers.

By following these steps, we can ensure that we are using the latest and most stable version of Docker and that our system is secure and up-to-date. 5)

Setting up Docker on CentOS

After installing Docker on CentOS, the next step is to set it up so that we can use it to manage containers.

This involves running Docker without using sudo and starting the Docker daemon.

Running Docker without sudo

The Docker command-line tool requires root privileges to function properly, which means that we need to use sudo each time we run a Docker command. However, we can avoid using sudo by adding our user to the Docker group.

To do this, we can run the following command:

“`

$ sudo usermod -aG docker $USER

“`

This command adds our user to the Docker group, giving us the necessary permissions to run Docker commands without using sudo. We need to log out and log back in for this change to take effect.

Starting Docker daemon

To start the Docker daemon, we can use the following command:

“`

$ sudo systemctl start docker

“`

This command starts the Docker daemon, allowing us to use Docker to manage containers. We can also enable Docker to start automatically at system boot by running the following command:

“`

$ sudo systemctl enable docker

“`

This command ensures that Docker starts automatically every time the system boots up.

6)

Verifying Docker installation

Once we have set up Docker on CentOS, we need to verify that it is working correctly. This involves running a few Docker commands to test that we can manage containers and that our installation is working properly.

Running hello-world container

To test Docker installation, we can run a hello-world container using the following command:

“`

$

docker run hello-world

“`

This command downloads and runs a small container that simply prints a message to the console. If the installation is successful, we should see a message indicating that Docker is working correctly.

Running Nginx server in a container

Another way to verify that Docker is working is to run an Nginx server in a container. To do this, we can use the following command:

“`

$ docker run -d –name my-nginx -p 80:80 nginx

“`

This command downloads and runs the Nginx server container and maps port 80 on the container to port 80 on the host.

We can then access the Nginx server by navigating to the IP address or hostname of our CentOS server on port 80.

Conclusion

In this article, we discussed how to set up Docker on CentOS and how to verify that it is working correctly. By adding our user to the Docker group and starting the Docker daemon, we can easily manage containers on our CentOS system.

By running a hello-world container and an Nginx server container, we can verify that Docker is installed and working correctly. By following these steps, we can ensure that our Docker installation is secure, up-to-date, and functioning properly.

In this article, we explored the process of installing Docker on CentOS and setting it up to manage containers. We discussed adding the official Docker repository, installing Docker CE and dependencies, running Docker without sudo, and starting the Docker daemon.

We also covered verifying Docker installation by running hello-world and Nginx server containers. By following these steps, we can ensure that our Docker installation is secure, up-to-date, and functioning properly.

The importance of proper setup and verification of Docker on CentOS cannot be overstated for efficient software development and secure implementation. Through adhering to these steps, developers can ensure the successful execution of containerized applications in different contexts and at scale.

Popular Posts