How to install docker on centos 7


Docker is an open-source project that automates the deployment of application inside the software container. The container allows the developer to package up all project resources such as libraries, dependencies, assets etc. Docker is written in Go Programming language and is developed by Dotcloud. It is basically a container engine which uses the Linux Kernel features like namespaces and control groups to create containers on top of an operating system and automates the application deployment on the container.

Installing Docker

Before installing Docker on CentOS, it is required to update CentOS packages. To update the packages, use the following commands-

# yum -y update

The sample output should be like this –

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.iitm.ac.in
* elrepo: mirrors.ircam.fr
* epel: mirror01.idc.hinet.net
* extras: ftp.iitm.ac.in
* updates: ftp.iitm.ac.in
Resolving Dependencies
--> Running transaction check
---> Package autocorr-en.noarch 1:4.3.7.2-5.el7 will be updated
---> Package autocorr-en.noarch 1:4.3.7.2-5.el7_2.1 will be an update
---> Package avahi.x86_64 0:0.6.31-15.el7 will be updated
---> Package avahi.x86_64 0:0.6.31-15.el7_2.1 will be an update
---> Package avahi-autoipd.x86_64 0:0.6.31-15.el7 will be updated
---> Package avahi-autoipd.x86_64 0:0.6.31-15.el7_2.1 will be an update
............

To install Docker, use the following command –

# yum -y install docker docker-registry

The sample output should be like this –

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.iitm.ac.in
* elrepo: mirrors.ircam.fr
* epel: epel.mirror.net.in
* extras: ftp.iitm.ac.in
* updates: ftp.iitm.ac.in
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 0:1.8.2-10.el7.centos will be installed
--> Processing Dependency: docker-selinux >= 1.8.2-10.el7.centos for package: docker-1.8.2-10.el7.centos.x86_64
---> Package docker-registry.x86_64 0:0.9.1-7.el7 will be installed
--> Processing Dependency: python-sqlalchemy >= 0.9.8-1 for package: docker-registry-0.9.1-7.el7.x86_64
--> Processing Dependency: python-backports-lzma >= 0.0.2-8 for package: docker-registry-0.9.1-7.el7.x86_64
--> Processing Dependency: python-requests for package: docker-registry-0.9.1-7.el7.x86_64
--> Processing Dependency: python-gunicorn for package: docker-registry-0.9.1-7.el7.x86_64
--> Processing Dependency: python-gevent for package: docker-registry-0.9.1-7.el7.x86_64
--> Processing Dependency: python-flask for package: docker-registry-0.9.1-7.el7.x86_64
--> Processing Dependency: python-blinker for package: docker-registry-0.9.1-7.el7.x86_64
--> Processing Dependency: m2crypto for package: docker-registry-0.9.1-7.el7.x86_64
--> Processing Dependency: PyYAML for package: docker-registry-0.9.1-7.el7.x86_64
.......

Starting Docker

To start Docker at boot, use the following command –

# systemctl enable docker.service

The sample output should be like this –

Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

To start the Docker, use the following command –

# systemctl start docker.service

To find the status of docker, use the following command –

# systemctl status docker.service

The sample output should be like this –

docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2016-02-29 16:01:24 IST; 1min 18s ago
Docs: http://docs.docker.com
Main PID: 27398 (docker)
CGroup: /system.slice/docker.service
└─27398 /usr/bin/docker daemon --selinux-enabled
Feb 29 16:00:56 linux docker[27398]: time="2016-02-29T16:00:56.139817103+05...e"
Feb 29 16:01:22 linux docker[27398]: time="2016-02-29T16:01:22.314033208+05...e"
Feb 29 16:01:22 linux docker[27398]: time="2016-02-29T16:01:22.314422184+05...e"
Feb 29 16:01:22 linux docker[27398]: time="2016-02-29T16:01:22.401448064+05...1"
Feb 29 16:01:22 linux docker[27398]: time="2016-02-29T16:01:22.647321427+05...e"
Feb 29 16:01:24 linux docker[27398]: time="2016-02-29T16:01:24.713353670+05...."
Feb 29 16:01:24 linux docker[27398]: time="2016-02-29T16:01:24.716886255+05...."
Feb 29 16:01:24 linux docker[27398]: time="2016-02-29T16:01:24.716900165+05...n"
Feb 29 16:01:24 linux docker[27398]: time="2016-02-29T16:01:24.716913621+05...os
Feb 29 16:01:24 linux systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
.........

Downloading Docker container for CentOS

To download Docker container, use the following command –

# docker pull centos

The sample output should be like this –

Using default tag: latest
Trying to pull repository docker.io/library/centos ... latest: Pulling from library/centos
47d44cb6f252: Pull complete
f5079557f135: Pull complete
42c2aa730369: Pull complete
0e0217391d41: Pull complete
library/centos:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:1272ae53bac7bf054dd209a0b4a8629bcc39526c2a767427c7639b630a224a9e
Status: Downloaded newer image for docker.io/centos:latest
.................

Running a Docker Container

To run a docker, it should require a basic CentOS container with a bash shell. To run a Docker, use the following command –

# docker run -i -t centos /bin/bash

The above command enters the user to a bash shell inside centOS docker container. To exit from the Docker, use Ctrl+p or Ctrl+q shortcuts. There are many communities which are already included in Docker container that can be found through a search.

For example, to search CentOS community, use the following command –

# docker search centos

The sample output should be like this –

INDEX       NAME                                  DESCRIPTION                                   STARS      OFFICIAL  AUTOMATED
docker.io   docker.io/centos                      The official build of CentOS.                 1965        [OK]
docker.io   docker.io/jdeathe/centos-ssh          CentOS-6 6.7 x86_64 / CentOS-7 7.2.1511 x8... 15                    [OK]
docker.io   docker.io/million12/centos-supervisor Base CentOS-7 with supervisord launcher, h... 9                     [OK]
docker.io   docker.io/blalor/centos               Bare-bones base CentOS 6.5 image 8                                  [OK]
docker.io   docker.io/nimmis/java-centos          This is docker images of CentOS 7 with dif... 7                     [OK]
docker.io   docker.io/torusware/speedus-centos    Always updated official CentOS docker imag... 7                     [OK]
docker.io   docker.io/centos/mariadb55-centos7 3                                                                      [OK]
docker.io   docker.io/nathonfowlie/centos-jre    Latest CentOS image with the JRE pre-insta...  3                     [OK]
docker.io   docker.io/nickistre/centos-lamp      LAMP on centos setup 3                                               [OK]
docker.io   docker.io/consol/sakuli-centos-xfce  Sakuli end-2-end testing and monitoring co...  2                     [OK]
docker.io   docker.io/darksheer/centos           Base Centos Image -- Updated hourly 1                                [OK]
docker.io   docker.io/layerworx/centos          CentOS container with etcd, etcdctl, confd...   1                     [OK]
docker.io   docker.io/lighthopper/orientdb-centos A Dockerfile for creating an OrientDB imag... 1                     [OK]
docker.io   docker.io/softvisio/centos Centos 1                                                                       [OK]
docker.io   docker.io/yajo/centos-epel          CentOS with EPEL and fully updated              1                     [OK]
docker.io   docker.io/blacklabelops/centos      CentOS Base Image! Built and Updates Daily!     0                     [OK]
docker.io   docker.io/dmglab/centos             CentOS with some extras - This is for the ...   0                     [OK]
docker.io   docker.io/ericuni/centos            centos dev                                      0                     [OK]
docker.io   docker.io/grayzone/centos           auto build for centos.                          0                     [OK]
docker.io   docker.io/insaneworks/centos        CentOS 6.5 x86_64 + @update                     0                     [OK]
docker.io   docker.io/januswel/centos           yum update-ed CentOS image                      0                     [OK]
docker.io   docker.io/jsmigel/centos-epel       Docker base image of CentOS w/ EPEL installed   0                     [OK]
docker.io   docker.io/lighthopper/openjdk-centos A Dockerfile for creating an OpenJDK image...  0                     [OK]
docker.io   docker.io/timhughes/centos          Centos with systemd installed and running       0                     [OK]
docker.io   docker.io/ustclug/centos            USTC centos                                     0                     [OK]

Congratulations! Now, you know “ How to install Docker on CentOS 7”. We’ll learn more about these types of commands in our next Linux post. Keep reading!

Lakshmi Srinivas
Lakshmi Srinivas

Programmer / Analyst / Technician

Updated on: 21-Oct-2019

263 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements