Install Docker on CentOS 7

This tutorial is going to cover how to install Docker on CentOS 7. There are several approaches for us:

  •  Install using Docker Repository
  • Install using RPM Package

We are going to get through both approaches and then additional Docker configurations.

1. Prerequisites

  •  The CentOS  7 must be 64-bits OS
  •  Kernel version should be 3.10 at minimum

You can do a quick check by issuing the following command:

Install Docker on CentOS 7.X - CentOS 7 Kernel Version

CentOS 7 Kernel Version

My CentOS 7 kernel version is 3.10.0. It’s good to get started.

  • Logged in user has sudo or root privileges

2. Install Docker on CentOS 7 using Docker Repository

By install Docker on CentOS 7 using repository, we firstly need to set up the Docker repository. Afterward, we can install, update, or downgrade Docker from the repository.

2.1. Setup The Docker Repository

Firstly, we need to install yum-utils, which provides the yum-config-manager utility:

Then, set up the stable repository by using the following command:

2.2. Install Docker

2.2.1. Update the Yum package index

2.2.2. Install the latest version of Docker or go to next step to install a specific version

2.2.3. Install a specific version of Docker

Step 1. List all available versions of Docker

The output will be similar to below:

Step 2. Install a specific version

We can install a specific version of Docker by appending the version string to the package name and separate them by a hyphen (-):

For example, let’s install the Docker version 1.12.6-1.el7.centos

2.3. Start the Docker

2.4. Verify the installation

Verify that docker is installed correctly by running the hello-world image

You should see the result that is similar as below image:

Install Docker on CentOS 7 - Running hello-world Docker

Running hello-world Docker

3. Install Docker on CentOS 7 using RPM Package

If for any reason that we cannot use Docker’s repository to install Docker on CentOS 7, we can download the .rpm file for our release and install it manually. By installing Docker this way, to upgrade Docker, we have to download the newer package and install it by ourselves.

3.1. Download the Docker RPM Package

Go to https://yum.dockerproject.org/repo/main/centos/, choose the subdirectory for your CentOS version and download the .rpm file for the Docker version we want to install.

For example, the following command will download the Docker RPM package 1.3.1-1

3.2. Install the Docker

The next step is to install the RPM package. We can change the path below to the path where we downloaded the Docker package:

4. Additional Configurations

4.1. Avoid using sudo command when use docker commands.

By default, docker deamon run with root user. To avoid using sudo when use docker commands, we will create a group docker and add user to that group. According to the docker document, when the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.

4.1.1. Create docker group

4.1.2. Add our desire user to that group.

We have just added the current user to the group.

4.1.3. Log out and log in again

4.1.4. Verify that we don’t need sudo anymore.

You can issue below command to check:

The output should be the same as step 2.3

4.2. Configure Docker to start on boot

You can do this by using below command:

or

5. Uninstall Docker

For any reason that you want to uninstall Docker on CentOS 7, you can do as following.

5.1. Uninstall the Docker package

5.2. Remove all images, containers, volumes, or customized configuration files on your host

We must delete any edited configuration files manually.

6. Conclusion

Above are simple steps to install Docker on CentOS 7 by using Docker repository or using RPM package. With the first approach, it’s is easier for us to upgrade or downgrade Docker while with the second approach, we must download and upgrade or downgrade manually by ourselves. Below are other articles related to Docker. If you’re interested in, you can refer to the following links:

Copy Files, Folders from Host to Docker Container and Vice Versa

How to Get IP Address of a Docker Container

How To Pull A Docker Image And Run A Container

Basic Docker commands

Install Docker on Ubuntu 16.04, 15.10, 14.04 Step By Step

Introduction to Docker Compose

Vagrant Docker Provider Tutorial

Using Apache Kafka Docker

Insecure docker registry