Sunday, May 20, 2018

Installing Docker CE on RHEL 7

RHEL is not listed as a platform for Docker CE. But it is still possible to install Docker CE on OEL7 and RHEL7 using the centOS repository.This post list the steps for installing Docker CE on RHEL7.
1. Install the following rpm if they are not already installed
yum install -y yum-utils device-mapper-persistent-data lvm2
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
redhatdvdiso                                                                                                                                                           | 4.1 kB  00:00:00
Package yum-utils-1.1.31-42.el7.noarch already installed and latest version
Package device-mapper-persistent-data-0.7.0-0.1.rc6.el7.x86_64 already installed and latest version
Package 7:lvm2-2.02.171-8.el7.x86_64 already installed and latest version
Nothing to do
2. Install container-selinux, which needs to be downloaded a separate extras package from redhat.
rpm -ivh container-selinux-2.42-1.gitad8f0f7.el7.noarch.rpm
warning: container-selinux-2.42-1.gitad8f0f7.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:container-selinux-2:2.42-1.gitad8################################# [100%]
3. Next requires the Extra Package for Enterprise Linux (EPEL) subscription. If one is not available or there's no spare subscription to be used with the server used for docker, then use OEL7 public repository. Add the following to /etc/yum.repos.d/oel7_EPEL.repo.
[ol7_developer_EPEL]
name=Oracle Linux $releasever Developement Packages ($basearch)
baseurl=http://yum.oracle.com/repo/OracleLinux/OL7/developer_EPEL/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=0 
enabled=1
Make sure gpgcheck=0, if not following error will be thrown during docker installation.
GPG key retrieval failed: [Errno 14] curl#37 - "Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle"
4. Download the docker CE repository for centOS.
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
5. Disable the bleeding edge features if not needed
yum-config-manager --disable docker-ce-edge
5. Install the docker-ce using yum.
# yum install docker-ce
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
ol7_developer_EPEL                               | 1.2 kB  00:00:00
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 0:18.03.1.ce-1.el7.centos will be installed
--> Processing Dependency: pigz for package: docker-ce-18.03.1.ce-1.el7.centos.x86_64
--> Running transaction check
---> Package pigz.x86_64 0:2.3.4-1.el7 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:
 pigz                                    x86_64                               2.3.4-1.el7                                              ol7_developer_EPEL                                80 k

Transaction Summary
==============================================================================================================================================================================================
Install  1 Package (+1 Dependent package)

Total size: 35 M
Installed size: 151 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : pigz-2.3.4-1.el7.x86_64                                                                                                                                                    1/2
  Installing : docker-ce-18.03.1.ce-1.el7.centos.x86_64                                                                                                                                   2/2
  Verifying  : docker-ce-18.03.1.ce-1.el7.centos.x86_64                                                                                                                                   1/2
  Verifying  : pigz-2.3.4-1.el7.x86_64                                                                                                                                                    2/2

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

Dependency Installed:
  pigz.x86_64 0:2.3.4-1.el7

Complete!


6. Start docker and run the hello-world image to verify the docker installation.
# systemctl start docker
# systemctl enable docker
# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/
7. At this stage docker is installing and running without any issue. If a user other than root needs to run docker, simply make that user part of the docker OS group. Following put oracle user into docker group.
# usermod -a -G docker oracle
# id oracle
uid=1000(oracle) gid=1002(oinstall) groups=1002(oinstall),1001(dba),1003(oper),985(docker)
8. By default docker images are created in /var/lib/docker. If this path is in / partition or in a parition that has limited space then it's better to move the docker root directory to different location. To do this stop docker and edit the docker service file by adding the new directory path to ExecStart.
#systemctl stop docker
vi /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --data-root /opt/docker

# systemctl daemon-reload
# systemctl start docker
# docker info

docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 17
Server Version: 18.03.1-ce
Storage Driver: overlay2
 Backing Filesystem: xfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 3.10.0-693.el7.x86_64
Operating System: Red Hat Enterprise Linux Server 7.4 (Maipo)
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 11.56GiB
Name: hpc3.domain.net
ID: Z3SI:SMHM:P7J7:623J:OGSR:7FNJ:SZGX:HN6X:R6NS:FXUB:BAQ6:XQCB
Docker Root Dir: /opt/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
This concludes installing docker-ce on RHEL 7.