How to Install Docker on CentOS 7 Linux systems

undefined

In this article, I’ll show you how to install Docker in CentOS 7 Linux system. This is your first step to get started with Docker engine on CentOS 7. I’ll use a minimal installation of CentOS 7 64bit to install Docker on it, of course the following installation steps are valid for all CentOS 7 installation types “Server without  Gui, Server with Gui, minimal, etc..”.
On this machine we will install Docker engine, allowing you to run a docker image (container) within docker engine.

Introduction to Docker.

Docker is an open-source tool that makes creating & managing Linux containers(LXC) easy. Containers are like lightweight VMs which can be started & stopped in milliseconds. Dockers help the system administrators & coders to develop their application in a container and can further scale up to 1000 of nodes. Working with Docker containers adds many benefits for developers: better separation of application and the server configuration.

The main difference between container and VM(Virtual machine) is that dockers provide process based isolation , whereas VM provides full isolation of resources. Virtual machine takes a minute to start where as container can be started in a second or less than a second. Container uses the Kernel of host OS , whereas VM uses the separate Kernel. Container uses less disk space and memory than VM.

Prerequisites

Docker requires a 64-bit OS and version 3.10 or higher of the Linux kernel. So, we need to check these two requirements against our CentOS 7 server.

To check your current kernel version and OS architecture, run the following command:

# uname -r
3.18.44-20.el7.x86_64

Perfect, our server is has the prerequisites for installing Docker. Let’s start our steps for installing Docker.

It is recommended that you fully update your system to ensure we have all recent packages – Docker likes to be on an up to date system – we start with a full system upgrade, run the following command:

# yum -y update

Now, we will add the Docker repository. This allows us to install the latest stable version of the Docker engine. You can EITHER copy and paste the following Lines into your terminal as root:

# tee /etc/yum.repos.d/docker.repo <<-'EOF'
 [dockerrepo]
 name=Docker Repository
 baseurl=https://yum.dockerproject.org/repo/main/centos/7/
 enabled=1
 gpgcheck=1
 gpgkey=https://yum.dockerproject.org/gpg
 EOF

OR With your favorite text editor, create the “docker.repo” file in the “/etc/yum.repos.d” repositories directory.

# vim /etc/yum.repos.d/docker.repo

In this file, copy the following content:

[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

Save the file!
Before leaving this step, let’s list all the repositories installed on our CentOS 7 machine, run the following command:

# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.airenetworks.es
 * epel: mirrors.ircam.fr
 * extras: mirror.airenetworks.es
 * updates: mirror.airenetworks.es
repo id repo name status
!base/7/x86_64 CentOS-7 - Base 9,353+10
!dockerrepo Docker Repository 48+32
*!epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 11,019
!extras/7/x86_64 CentOS-7 - Extras 435
!updates/7/x86_64 CentOS-7 - Updates 423+10
repolist: 24,594

As you see, Docker Repository exists.

We can install docker-engine with the following command:

# yum -y install docker-engine

The Docker engine is now installed on CentOS 7, we need to enable it to run at boot and start the service, run the following commands:

# systemctl enable docker
# systemctl start docker
Hints: 

1. If you want normal user to use docker, you need to add this normal user to the docker group.
2. By adding a user to the docker group, you'll have a full privileges on different docker commands, See the following optional step.

Step 5: Running Docker with Normal User Privileges “Optional”

You need to add your normal user to the docker group created by default when we installed the Docker packages. Here’s I’ll add user “msemari” to docker group:

# usermod -aG docker msemari

Now, logout and login again using this user “your normal user” and enjoy playing with Docker.

  1. List the installed Docker packages.
    # yum list installed | grep docker
    
    docker-engine.x86_64                   1.12.3-1.el7.centos             @dockerrepo
    docker-engine-selinux.noarch           1.12.3-1.el7.centos             @dockerrepo
    
  2. Remove the package.
    # yum -y remove docker-engine.x86_64
    # yum -y remove docker-engine-selinux.noarch
    

    This command does not remove images, containers, volumes, or user-created configuration files on your host.

  3. To delete all images, containers, and volumes, run the following command:
    # rm -rf /var/lib/docker
    
  4. Locate and delete any user-created configuration files.

Summary

I think, Docker if the future replacement of the VMs as it’s a lightweight server, it do not need a dedicated memory or disk or CPU power. Your server can run number of containers higher than the number of VMs with same server’s hardware. Personally, I’m moving from using VMs to use Docker containers to save my machines resources. Finally, with help of this article you could install Docker engine and enable, start it. I also included how to completely remove Docker packages.

If You Appreciate What We Do Here On Mimastech, You Should Consider:

  1. Stay Connected to: Facebook | Twitter | Google+
  2. Support us via PayPal Donation
  3. Subscribe to our email newsletters.
  4. Tell other sysadmins / friends about Us - Share and Like our posts and services

We are thankful for your never ending support.

Leave a Reply

Your email address will not be published. Required fields are marked *