How to Install Docker in CentOS 7

install docker in centos
Share

If you develop and deploy apps on CentOS 7 servers, you might have heard the term Docker mentioned a lot these days.

If you’re curious about all the buzz around using Docker for app deployment in isolated virtual environments, this article is for you. We’ll explore Docker and the benefits it brings to application deployment. We’ll also show you how to install Docker in CentOS 7 environment in a few simple steps.

What is Docker?

The term Docker refers to a very popular set of Platform-as-a-Service products that create and manage containers (isolated virtual environments for building, deploying, and managing applications).

Developers prefer containers because they combine all resources in a single environment, including the OS and required libraries. As a result, the application can be deployed and executed without worrying about dependencies and similar issues. Containerized applications are especially popular in cloud and hybrid environments where developers and sysadmins need a way to work around code dependencies and OS-level services.

While developers can bundle everything from the OS kernel and all required libraries in a single deployment package, Docker greatly simplifies and speeds up the process. Containerized applications come with all the benefits of virtual machines without the performance overheads of higher resource consumption.

Benefits of Using Docker Containers

Docker containers come with several benefits that streamline application development and deployment.

Minimal Overhead

Containers usually don’t contain primary OS images. Generally, they have a minimized subset of guest OS required by the application. In contrast, a VM requires a full OS image that adds to the size and performance of the VM. As a general rule of thumb, a VM can be in GBs, while a typical container is just in MBs.

Improved Application Portability

Containerized applications can be easily deployed to any OS and hardware environment without worrying about conflicts and missed dependencies. Improved app portability also results in faster application deployment and simplified maintenance.

Smooth Application Management

Sysadmins often find containerized applications easier to manage than traditionally deployed and VM-deployed apps. Containerized apps can be deployed faster and patched more easily and quickly than other options.

Consistent App Behavior

Dockers containers ensure that the apps deployed within behave consistently regardless of the OS and hardware platforms they’re deployed on.

Better Application Development

Thanks to the bundling of everything the app needs, developers can create a container and rest easy about dependencies and conflicts. In addition, Containerized apps are generally write-once-deploy-everywhere and a much better fit for CI/CD pipelines.

Now that you have a fair idea of the benefits of Docker containers, it is time to dive into the process you can follow to install Dockers in CentoOS 7.

Process Prerequisites

To properly install Docker in CentOS 7 server, you need:

  • A 64-bit CentOS 7 server with kernel version 3.10 or better

While you need superuser (sudo) privileges, we recommend running the process as a non-root user.

Install Docker in Centos 7 in Five Easy Steps

The process of installing Docker in CentOS 7 environment is pretty straightforward. First, you download the repo and then install the package.

Let’s go into the details of the process.

Step 1: Update all packages on the server
The first thing to do when installing DOckers on CentOS 7 server is to ensure all packages are updated. This important precaution helps you avoid any process failures due to missing dependencies.

To update all the packages on the server, use the following command:

# yum update

Step 2: Install The Docker Repository

When installing, you first need to add the official Docker repository to your CentOS machine. This will ensure that we have the latest version.

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

Next, install the Docker Community Edition on the machine. For this, use the following command.

# yum install docker-ce

There might be scenarios where you want a specific Docker version. For this, get the version number and add the -<VERSION> switch at the end of the command. For instance, try the following command to install Docker CE version 18.03.0

# yum install docker-ce-18.03.0.ce

Step 3: Create a User

We recommend creating a non-root user for using Docker. This simple precaution helps you avoid a lot of headaches that come with unintentional mistakes. Use the following command to add a non-root user for running Docker.

# adduser Redswitches

Now, you need to add this user to the Docker group. Use the usermod command:

# usermod -aG docker Redswitches

Step 4: Start the Docker Service

At this point, you’ve installed Docker and added a non-root user to the Docker group. Next, it is time to start the Docker daemon. For this, use the following command:

# systemctl start docker

Step 5: Verify that Docker is Active on Your System

Since systemctl doesn’t return a status you really don’t have any idea if the Docker daemon is successfully activated. To verify this, we suggest you run Docker’s version of Hello World.

# docker run hello-world

During this command’s execution, Docker downloads a test image and runs it in a container. If the setup has been successful and the demon is successfully up and running, you’ll see the following message:

Hello from Docker.

This message shows that your installation appears to be working correctly.

Optional
If you wish, you can enable Docker to run after the system starts. For this, use the following command:

# chkconfig docker on

Conclusion

Docker is a powerful solution for developing and deploying your apps on any server. You don’t have to worry about the underlying OS and dependencies because Docker containerized apps are a complete package that contains everything the app requires. This simple guide covered the process of installing Docker on CentOS 7 server. Let us know if you need help setting up Docker or CentOS 7 on your RedSwitches bare metal server, let us know, and our engineers will take care of the task.