X
    Categories: devops

How to install Docker on Linux (RHEL Centos Ubuntu Debian)


In this article we will be discussing step by step guide to install docker on Linux on various flavours such as RHEL/Centos/Ubuntu/Debian.


Kindly note that there are two types of Docker available in the market CE (Community Edition (CE) is ideal for developers and small teams)and EE (Enterprise Edition (EE) 2.0 is the only enterprise-ready). So in case your operating system is Enterprise level then you cannot install CE version of docker. You can only intall EE type of Docker on it.

Docker is an containerised environment which can be installed on OS like Linux, Windows and even on Mac also using which we can run many services using images. Please follow this article to know more about Docker.

Steps to Install Docker on Linux ( RHEL and Centos).

1. Firstly install device mapper that gives us ability to use different types of storage sub-systems for containers and also lvm2.

#yum install -y yum-utils device-mapper-persistent lvm2

2.  Add official docker repository using below command:

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

Note: This will add community edition repo in case you want to install enterprise edition change ce to ee in the above command.

3. Perform the yum update using below command.

#yum update

4. Finally install docker ce using below command:

#yum install docker-ce

Installation logs:

[root@centos ~]# yum install docker-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.fibergrid.in
 * extras: mirrors.fibergrid.in
 * updates: mirrors.fibergrid.in
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 0:18.03.1.ce-1.el7.centos will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: docker-ce-18.03.1.ce-1.el7.centos.x86_64
--> Processing Dependency: pigz for package: docker-ce-18.03.1.ce-1.el7.centos.x86_64
--> Processing Dependency: libltdl.so.7()(64bit) for package: docker-ce-18.03.1.ce-1.el7.centos.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.55-1.el7 will be installed
---> Package libtool-ltdl.x86_64 0:2.4.2-22.el7_3 will be installed
---> Package pigz.x86_64 0:2.3.3-1.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                                  Arch                          Version                                           Repository                               Size
========================================================================================================================================================================
Installing:
 docker-ce                                x86_64                        18.03.1.ce-1.el7.centos                           docker-ce-stable                         35 M
Installing for dependencies:
 container-selinux                        noarch                        2:2.55-1.el7                                      extras                                   34 k
 libtool-ltdl                             x86_64                        2.4.2-22.el7_3                                    base                                     49 k
 pigz                                     x86_64                        2.3.3-1.el7.centos                                extras                                   68 k

Transaction Summary
========================================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 35 M
Installed size: 151 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): container-selinux-2.55-1.el7.noarch.rpm                                                                                                   |  34 kB  00:00:00
(2/4): libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm                                                                                                    |  49 kB  00:00:00
(3/4): pigz-2.3.3-1.el7.centos.x86_64.rpm                                                                                                        |  68 kB  00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY0:00 ETA
Public key for docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm is not installed
(4/4): docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm                                                                                              |  35 MB  00:00:01
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                    21 MB/s |  35 MB  00:00:01
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 From       : https://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : pigz-2.3.3-1.el7.centos.x86_64                                                                                                                       1/4
  Installing : 2:container-selinux-2.55-1.el7.noarch                                                                                                                2/4
  Installing : libtool-ltdl-2.4.2-22.el7_3.x86_64                                                                                                                   3/4
  Installing : docker-ce-18.03.1.ce-1.el7.centos.x86_64                                                                                                             4/4
  Verifying  : libtool-ltdl-2.4.2-22.el7_3.x86_64                                                                                                                   1/4
  Verifying  : docker-ce-18.03.1.ce-1.el7.centos.x86_64                                                                                                             2/4
  Verifying  : 2:container-selinux-2.55-1.el7.noarch                                                                                                                3/4
  Verifying  : pigz-2.3.3-1.el7.centos.x86_64                                                                                                                       4/4

Installed:
  docker-ce.x86_64 0:18.03.1.ce-1.el7.centos

Dependency Installed:
  container-selinux.noarch 2:2.55-1.el7                    libtool-ltdl.x86_64 0:2.4.2-22.el7_3                    pigz.x86_64 0:2.3.3-1.el7.centos

Complete!
[root@centos ~]#

5. Now enable and start the docker using below command:

# systemctl enable docker && systemctl start docker

6. In case you want to check the current status of the docker fire below command:

# systemctl status docker

7. If you would like to use Docker as a non-root user(manmohan user in my case), you should now consider
adding your user to the “docker” group with something like this so that normal user can able to run docker commands:

# usermod -aG docker manmohan

8. Check current version of docker with below command:

[root@centos ~]# docker --version
Docker version 18.03.1-ce, build 9ee9f40
[root@centos ~]# su - manmohan
[manmohan@centos ~]$ docker --version
Docker version 18.03.1-ce, build 9ee9f40

Steps to Install Docker on Linux ( Ubuntu and Debian).

1. Install packages to allow apt to use a repository over HTTPS:

#apt-get install apt-transport-https ca-certificates curl software-properties-common

2. Pull Docker’s official GPG key:

#curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

3. Use the following command to set up the stable repository.

#add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

4. Update the apt package index.

#apt-get update

5. Install the latest version of Docker CE using below command:

#apt-get install docker-ce

Installation logs:

root@ubuntu:~# apt-get install docker-ce
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  aufs-tools cgroupfs-mount libltdl7 pigz
Suggested packages:
  mountall
The following NEW packages will be installed:
  aufs-tools cgroupfs-mount docker-ce libltdl7 pigz
0 upgraded, 5 newly installed, 0 to remove and 31 not upgraded.
Need to get 34.2 MB of archives.
After this operation, 182 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://download.docker.com/linux/ubuntu xenial/stable amd64 docker-ce amd64 18.03.1~ce-0~ubuntu [34.0 MB]
Get:2 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu xenial/universe amd64 pigz amd64 2.3.1-2 [61.1 kB]
Get:3 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu xenial/universe amd64 aufs-tools amd64 1:3.2+20130722-1.1ubuntu1 [92.9 kB]
Get:4 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu xenial/universe amd64 cgroupfs-mount all 1.2 [4,970 B]
Get:5 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu xenial/main amd64 libltdl7 amd64 2.4.6-0.1 [38.3 kB]
Fetched 34.2 MB in 1s (31.3 MB/s)
Selecting previously unselected package pigz.
(Reading database ... 51260 files and directories currently installed.)
Preparing to unpack .../pigz_2.3.1-2_amd64.deb ...
Unpacking pigz (2.3.1-2) ...
Selecting previously unselected package aufs-tools.
Preparing to unpack .../aufs-tools_1%3a3.2+20130722-1.1ubuntu1_amd64.deb ...
Unpacking aufs-tools (1:3.2+20130722-1.1ubuntu1) ...
Selecting previously unselected package cgroupfs-mount.
Preparing to unpack .../cgroupfs-mount_1.2_all.deb ...
Unpacking cgroupfs-mount (1.2) ...
Selecting previously unselected package libltdl7:amd64.
Preparing to unpack .../libltdl7_2.4.6-0.1_amd64.deb ...
Unpacking libltdl7:amd64 (2.4.6-0.1) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../docker-ce_18.03.1~ce-0~ubuntu_amd64.deb ...
Unpacking docker-ce (18.03.1~ce-0~ubuntu) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu21.2) ...
Setting up pigz (2.3.1-2) ...
Setting up aufs-tools (1:3.2+20130722-1.1ubuntu1) ...
Setting up cgroupfs-mount (1.2) ...
Setting up libltdl7:amd64 (2.4.6-0.1) ...
Setting up docker-ce (18.03.1~ce-0~ubuntu) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Processing triggers for systemd (229-4ubuntu21.2) ...
Processing triggers for ureadahead (0.100.0-19) ...

6. If you would like to use Docker as a non-root user(manmohan user in my case), you should now consider
adding your user to the “docker” group with something like this so that normal user can able to run docker commands:

# usermod -aG docker manmohan

7. Check current version of Docker using below command:

$ docker --version
Docker version 18.03.1-ce, build 9ee9f40
$

In this way we can able to Install Docker on Linux with various flavours such as RHEL/Centos/Ubuntu and Debian.

Related Post