How to install Docker on CentOS 7

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 admin & coders to develop their application in a container and can further scale up to 1000 of nodes.

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.

One of the limitation of Docker is that it can be used only on 64bit hosts OS.

In this post we will discuss how to install docker in CentOS 7.x

Installation of Docker on CentOS 7

Docker package is included in the default CentOS-Extras repository. So to install docker , simply run below yum command :

[root@localhost ~]# yum install docker

Installation Steps of Docker CE (Community Edition) on CentOS 7

If you looking for stable and latest version Docker then you should go for Docker CE. Below are the steps how to install Docker CE.

Set the repository for Docker Community Edition

First install the required packages for setting up Docker Community edition repo using the following command

[root@localhost ~]# yum install yum-utils device-mapper-persistent-data lvm2 -y

Run the beneath command to set the stable repository of Docker CE (Community edition)

[root@localhost ~]# yum-config-manager --add-repo  https://download.docker.com/linux/centos/docker-ce.repo

Now use the following yum command to install Docker CE.

[root@localhost ~]# yum install docker-ce –y

Verify the Docker Version using the beneath command

[root@localhost ~]# docker --version
Docker version 17.06.0-ce, build 02c1d87
[root@localhost ~]#

Start the Docker Service

Once the Installation is finished , start docker service and enable it at boot using below commands

[root@localhost ~]# systemctl start docker && systemctl enable docker

Download the official Centos images Locally

[root@localhost ~]# docker pull centos
Pulling repository centos
192178b11d36: Download complete 
70441cac1ed5: Download complete 
ae0c2d0bdc10: Download complete 
511136ea3c5a: Download complete 
5b12ef8fd570: Download complete

 Verify CentOS images that have been fetched :

[root@localhost ~]# docker images centos
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              centos5             192178b11d36        2 weeks ago         466.9 MB
centos              centos6             70441cac1ed5        2 weeks ago         215.8 MB
centos              centos7             ae0c2d0bdc10        2 weeks ago         224 MB
centos              latest              ae0c2d0bdc10        2 weeks ago         224 MB

Run a Docker Container :

[root@localhost ~]# docker run -i -t centos /bin/bash
[root@dbf66395436d /]#

As we can see centos container has been started and we got the bash shell. In docker command we have used options like ‘-i attaches stdin and stdout’ and ‘-t allocates a terminal or console’ . To disconnect from container type exit .

[root@cd05639b3f5c /]# cat /etc/redhat-release 
CentOS Linux release 7.0.1406 (Core) 
[root@cd05639b3f5c /]# exit
exit
[root@localhost ~]#

We can also search Containers based on fedora & ubuntu OS.

[root@localhost ~]# docker search ubuntu
[root@localhost ~]# docker search fedora

Display the list of running containers

docker-ps

Leave a Comment

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