Sunday, 8 July 2018

007- Installing OpenShift

Install OpenShift packages:

[root@master ~]# yum install atomic-openshift-docker-excluder atomic-openshift-excluder atomic-openshift-utils bridge-utils bind-utils git iptables-services net-tools wget

[root@node1 ~]# yum install atomic-openshift-docker-excluder atomic-openshift-excluder atomic-openshift-utils bridge-utils bind-utils git iptables-services net-tools wget

"atomic-openshift-docker-excluder" RPM will be used to avoid changing docker-related packages versions upgrade unless we want that:
[root@master ~]# grep exclude /etc/yum.conf 
exclude= docker*1.20*  docker*1.19*  docker*1.18*  docker*1.17*  docker*1.16*  docker*1.15*  docker*1.14*  docker*1.13*  tuned-profiles-atomic-openshift-node  atomic-openshift-tests  atomic-openshift-sdn-ovs  atomic-openshift-recycle  atomic-openshift-pod  atomic-openshift-node  atomic-openshift-master  atomic-openshift-dockerregistry  atomic-openshift-clients-redistributable  atomic-openshift-clients  atomic-openshift 

"atomic-openshift-excluder" RPM will be used to avoid changing openshift-related packages versions upgrade unless we want that:
[root@master ~]# grep exclude /etc/yum.conf 
exclude= docker*1.20*  docker*1.19*  docker*1.18*  docker*1.17*  docker*1.16*  docker*1.15*  docker*1.14*  docker*1.13*  tuned-profiles-atomic-openshift-node  atomic-openshift-tests  atomic-openshift-sdn-ovs  atomic-openshift-recycle  atomic-openshift-pod  atomic-openshift-node  atomic-openshift-master  atomic-openshift-dockerregistry  atomic-openshift-clients-redistributable  atomic-openshift-clients  atomic-openshift 


Remove all openshift-related packages from "/etc/yum.conf" exclude list on the two nodes:

[root@master ~]# atomic-openshift-excluder --help
[...]
unexclude | enable
  removes atomic-openshift atomic-openshift-clients atomic-openshift-clients-redistributable atomic-openshift-dockerregistry atomic-openshift-master atomic-openshift-node atomic-openshift-pod atomic-openshift-recycle atomic-openshift-sdn-ovs atomic-openshift-tests tuned-profiles-atomic-openshift-node from the exclude= line in /etc/yum.conf
  This re-enables updates for packages
[...]
status
  returns status either 'exclude' or 'unexclude' and 0 or 1 respectively


[root@master ~]# atomic-openshift-excluder unexclude


[root@master ~]# grep exclude /etc/yum.conf 
exclude= docker*1.20*  docker*1.19*  docker*1.18*  docker*1.17*  docker*1.16*  docker*1.15*  docker*1.14*  docker*1.13* 
[root@node1 ~]# atomic-openshift-excluder unexclude


[root@node1 ~]# grep exclude /etc/yum.conf
exclude= docker*1.20*  docker*1.19*  docker*1.18*  docker*1.17*  docker*1.16*  docker*1.15*  docker*1.14*  docker*1.13* 


Install OpenShift:


0005- Install Docker

Create SSH keys for the two nodes:

[root@master ~]# ssh-keygen -f /root/.ssh/id_rsa -t rsa -N ''

[root@master ~]# ls -lh .ssh/
total 8.0K
-rw-------. 1 root root 1.7K Jul  8 12:33 id_rsa
-rw-r--r--. 1 root root  400 Jul  8 12:33 id_rsa.pub

[root@master ~]# ssh-copy-id node1
[root@node1 ~]# ssh-keygen -f /root/.ssh/id_rsa -t rsa -N ''

[root@node1 ~]# ls -lh .ssh/
total 8.0K
-rw-------. 1 root root 1.7K Jul  8 12:33 id_rsa
-rw-r--r--. 1 root root  400 Jul  8 12:33 id_rsa.pub

[root@node1 ~]# ssh-copy-id master


Install docker on both nodes:

[root@master ~]# yum install docker-1.12.6 -y
[root@node1 ~]# yum install docker-1.12.6 -y


Disable LVM cluster feature on both nodes:

[root@master ~]# lvmconf --disable-cluster 
[root@master ~]# echo $?
0
[root@node1 ~]# lvmconf --disable-cluster
[root@node1 ~]# echo $?
0


Configure Docker storage to use logical volume will be created on "/dev/vdb" disk for both nodes:

[root@master ~]# fdisk -l /dev/vdb

Disk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


[root@master ~]# cp -av /etc/sysconfig/docker-storage-setup /root/orig_files/
‘/etc/sysconfig/docker-storage-setup’ -> ‘/root/orig_files/docker-storage-setup’


[root@master ~]# grep -v ^# /etc/sysconfig/docker-storage-setup | awk NF
CONTAINER_THINPOOL=docker-pool


[root@master ~]# vim /etc/sysconfig/docker-storage-setup 


[root@master ~]# grep -v ^# /etc/sysconfig/docker-storage-setup | awk NF
DEVS=vdb
VG=docker-vg


[root@master ~]# docker-storage-setup 
INFO: Writing zeros to first 4MB of device /dev/vdb
4+0 records in
4+0 records out
4194304 bytes (4.2 MB) copied, 0.256067 s, 16.4 MB/s
INFO: Device node /dev/vdb1 exists.
  Physical volume "/dev/vdb1" successfully created.
  Volume group "docker-vg" successfully created
  Using default stripesize 64.00 KiB.
  Rounding up size to full physical extent 44.00 MiB
  Thin pool volume with chunk size 512.00 KiB can address at most 126.50 TiB of data.
  Logical volume "docker-pool" created.
  Logical volume docker-vg/docker-pool changed.


[root@master ~]# pvs
  PV         VG          Fmt  Attr PSize   PFree 
  /dev/vda2  rhel_master lvm2 a--  <79.00g  4.00m
  /dev/vdb1  docker-vg   lvm2 a--  <40.00g 24.00g


[root@master ~]# vgs
  VG          #PV #LV #SN Attr   VSize   VFree 
  docker-vg     1   1   0 wz--n- <40.00g 24.00g
  rhel_master   1   3   0 wz--n- <79.00g  4.00m


[root@master ~]# lvs
  LV          VG          Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  docker-pool docker-vg   twi-a-t---  15.91g             0.00   0.09                            
  home        rhel_master -wi-ao----  23.33g                                                    
  root        rhel_master -wi-ao---- <47.79g                                                    
  swap        rhel_master -wi-ao----  <7.88g   

[root@master ~]# cat /etc/sysconfig/docker-storage
DOCKER_STORAGE_OPTIONS="--storage-driver devicemapper --storage-opt dm.fs=xfs --storage-opt dm.thinpooldev=/dev/mapper/docker--vg-docker--pool --storage-opt dm.use_deferred_removal=true --storage-opt dm.use_deferred_deletion=true "
[root@node1 ~]# fdisk -l /dev/vdb
Disk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


[root@node1 ~]# cp -av /etc/sysconfig/docker-storage-setup /root/orig_files/
‘/etc/sysconfig/docker-storage-setup’ -> ‘/root/orig_files/docker-storage-setup’


[root@node1 ~]# grep -v ^# /etc/sysconfig/docker-storage-setup | awk NF
CONTAINER_THINPOOL=docker-pool


[root@node1 ~]# vim /etc/sysconfig/docker-storage-setup 


[root@node1 ~]# grep -v ^# /etc/sysconfig/docker-storage-setup | awk NF
DEVS=vdb
VG=docker-vg


[root@node1 ~]# docker-storage-setup 
INFO: Writing zeros to first 4MB of device /dev/vdb
4+0 records in
4+0 records out
4194304 bytes (4.2 MB) copied, 0.273737 s, 15.3 MB/s
INFO: Device node /dev/vdb1 exists.
  Physical volume "/dev/vdb1" successfully created.
  Volume group "docker-vg" successfully created
  Using default stripesize 64.00 KiB.
  Rounding up size to full physical extent 44.00 MiB
  Thin pool volume with chunk size 512.00 KiB can address at most 126.50 TiB of data.
  Logical volume "docker-pool" created.
  Logical volume docker-vg/docker-pool changed.


[root@node1 ~]# pvs
  PV         VG         Fmt  Attr PSize   PFree 
  /dev/vda2  rhel_node1 lvm2 a--  <39.00g  4.00m
  /dev/vdb1  docker-vg  lvm2 a--  <40.00g 24.00g


[root@node1 ~]# vgs
  VG         #PV #LV #SN Attr   VSize   VFree 
  docker-vg    1   1   0 wz--n- <40.00g 24.00g
  rhel_node1   1   2   0 wz--n- <39.00g  4.00m


[root@node1 ~]# lvs
  LV          VG         Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  docker-pool docker-vg  twi-a-t---  15.91g             0.00   0.09                            
  root        rhel_node1 -wi-ao---- <35.12g                                                    
  swap        rhel_node1 -wi-ao----  <3.88g                                                    


[root@node1 ~]# cat /etc/sysconfig/docker-storage
DOCKER_STORAGE_OPTIONS="--storage-driver devicemapper --storage-opt dm.fs=xfs --storage-opt dm.thinpooldev=/dev/mapper/docker--vg-docker--pool --storage-opt dm.use_deferred_removal=true --storage-opt dm.use_deferred_deletion=true "


Enable and Start "docker" service on both nodes:

[root@master ~]# systemctl enable docker --now
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

[root@master ~]# systemctl status  docker --now
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2018-07-08 12:49:49 CEST; 5s ago
     Docs: http://docs.docker.com
 Main PID: 2541 (dockerd-current)
   CGroup: /system.slice/docker.service
           ├─2541 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --authorization-plugin=rhel-push-plugin --ex...
           └─2549 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim --metrics-interval=0 --start-timeout ...
[root@node1 ~]# systemctl enable docker --now
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

[root@node1 ~]# systemctl status  docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2018-07-08 12:55:17 CEST; 6s ago
     Docs: http://docs.docker.com
 Main PID: 2485 (dockerd-current)
   CGroup: /system.slice/docker.service
           ├─2485 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --authorization-plu...
           └─2491 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim --metrics-in...


Create cold snapshots:

[root@master ~]# poweroff 

[root@node1 ~]# poweroff 
virsh # snapshot-create-as openshift-master 03_docker --description "After installaing and enable docker-1.12.6"
Domain snapshot 03_docker created

virsh # snapshot-create-as openshift-node1 03_docker --description "After installaing and enable docker-1.12.6"
Domain snapshot 03_docker created

virsh # snapshot-list openshift-master
 Name                 Creation Time             State
------------------------------------------------------------
 00_fresh_os          2018-07-07 11:47:50 +0200 shutoff
 01_ready_to_install  2018-07-07 12:25:48 +0200 shutoff
 02_dnsmasq           2018-07-08 12:25:15 +0200 shutoff
 03_docker            2018-07-08 12:59:00 +0200 shutoff


virsh # snapshot-list openshift-node1
 Name                 Creation Time             State
------------------------------------------------------------
 00_fresh_os          2018-07-07 12:49:20 +0200 shutoff
 01_ready_to_install  2018-07-07 12:55:12 +0200 shutoff
 02_dnsmasq           2018-07-08 12:31:43 +0200 shutoff
 03_docker            2018-07-08 12:59:08 +0200 shutoff

Saturday, 7 July 2018

0004 - DNSMASQ

Overview:















"master" node Installation and configuration:

[root@master ~]# yum install dnsmasq bind-utils -y 

edit "/etc/dnsmasq.conf" configuration file":
[root@master ~]# cp -av /etc/dnsmasq.conf /root/orig_files/
‘/etc/dnsmasq.conf’ -> ‘/root/orig_files/dnsmasq.conf’

[root@master ~]# hostname
master.ab.lab

[root@master ~]# grep -v ^# /etc/dnsmasq.conf  | awk NF
conf-dir=/etc/dnsmasq.d,.rpmnew,.rpmsave,.rpmorig
[root@master ~]# vim /etc/dnsmasq.conf 
[root@master ~]# grep -B3 "^resolv-file" /etc/dnsmasq.conf 
# Change this line if you want dns to get its upstream servers from
# somewhere other that /etc/resolv.conf
#resolv-file=
resolv-file=/etc/resolv.dnsmasq
[root@master ~]# grep -B4 "^address" /etc/dnsmasq.conf 
# Add domains which you want to force to an IP address here.
# The example below send any host in double-click.net to a local
# web-server.
#address=/double-click.net/127.0.0.1
address=/ocp.master.ab.lab/192.168.11.162
[root@master ~]# grep -v ^# /etc/dnsmasq.conf  | awk NF
resolv-file=/etc/resolv.dnsmasq
address=/ocp.master.ab.lab/192.168.11.162
conf-dir=/etc/dnsmasq.d,.rpmnew,.rpmsave,.rpmorig

Create "/etc/resolv.dnsmasq" file:
[root@master ~]# vim /etc/resolv.dnsmasq

[root@master ~]# cat /etc/resolv.dnsmasq 
# Add the gateway as a name server
nameserver 192.168.11.1

Edit "/etc/sysconfig/network-scripts/ifcfg-eth0" and "/etc/NetworkManager/NetworkManager.conf" filesto avoid updating the "/etc/resolv.conf" file:
[root@master ~]# cp -av /etc/sysconfig/network-scripts/ifcfg-eth0 /root/orig_files/
‘/etc/sysconfig/network-scripts/ifcfg-eth0’ -> ‘/root/orig_files/ifcfg-eth0’

[root@master ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=2bd9f367-9099-4bb6-acb6-2ab3e635173a

[root@master ~]# vim   /etc/sysconfig/network-scripts/ifcfg-eth0 

[root@master ~]# cat   /etc/sysconfig/network-scripts/ifcfg-eth0 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=2bd9f367-9099-4bb6-acb6-2ab3e635173a
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.11.162
PREFIX=24
GATEWAY=192.168.11.1
##DNS1=192.168.11.1              <-----
PEERDNS=no                       <-----
[root@master ~]# cp -av /etc/NetworkManager/NetworkManager.conf /root/orig_files/
‘/etc/NetworkManager/NetworkManager.conf’ -> ‘/root/orig_files/NetworkManager.conf’


[root@master ~]# grep -v ^# /etc/NetworkManager/NetworkManager.conf | awk NF
[main]
plugins=ifcfg-rh
[logging]


[root@master ~]# vim /etc/NetworkManager/NetworkManager.conf 

[root@master ~]# grep -v ^# /etc/NetworkManager/NetworkManager.conf | awk NF
[main]
plugins=ifcfg-rh
dns=none                       <-----
[logging]

Edit "/etc/resolv.conf" file to set the "DNS" to be "127.0.0.1"file:
[root@master ~]# cp -av  /etc/resolv.conf /root/orig_files

[root@master ~]# cat /etc/resolv.conf 
# Generated by NetworkManager
search openshift ab.lab
nameserver 192.168.11.1

[root@master ~]# vim /etc/resolv.conf 
[root@master ~]# cat /etc/resolv.conf 
search  ab.lab
nameserver 127.0.0.1

Disable and stop "firewalld" service:
[root@master ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@master ~]# systemctl stop firewalld

Start and enable the "dnsmasq" service:
[root@master ~]# ip a
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:3f:27:ac brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.203/24 brd 192.168.11.255 scope global dynamic eth0
       valid_lft 2980sec preferred_lft 2980sec
    inet 192.168.11.162/24 brd 192.168.11.255 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe3f:27ac/64 scope link 
       valid_lft forever preferred_lft forever

[root@master ~]# dnsmasq --test
dnsmasq: syntax check OK.

[root@master ~]# systemctl enable dnsmasq --now
Created symlink from /etc/systemd/system/multi-user.target.wants/dnsmasq.service to /usr/lib/systemd/system/dnsmasq.service.

[root@master ~]# systemctl status dnsmasq 
● dnsmasq.service - DNS caching server.
   Loaded: loaded (/usr/lib/systemd/system/dnsmasq.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2018-07-08 11:56:54 CEST; 8s ago
 Main PID: 10900 (dnsmasq)
   CGroup: /system.slice/dnsmasq.service
           └─10900 /usr/sbin/dnsmasq -k

Jul 08 11:56:54 master.ab.lab systemd[1]: Started DNS caching server..
Jul 08 11:56:54 master.ab.lab systemd[1]: Starting DNS caching server....
Jul 08 11:56:54 master.ab.lab dnsmasq[10900]: started, version 2.76 cachesize 150
Jul 08 11:56:54 master.ab.lab dnsmasq[10900]: compile time options: IPv6 GNU-getopt DBus no-i18n IDN DHCP DHCPv6 no-Lua TFTP no-conntrack ipset auth no-DNSSEC loop-detect inotify
Jul 08 11:56:54 master.ab.lab dnsmasq[10900]: reading /etc/resolv.dnsmasq
Jul 08 11:56:54 master.ab.lab dnsmasq[10900]: using nameserver 192.168.11.1#53
Jul 08 11:56:54 master.ab.lab dnsmasq[10900]: read /etc/hosts - 2 addresses

Edit "/etc/hosts" file:
[root@master ~]# cp -av /etc/hosts /root/orig_files/
‘/etc/hosts’ -> ‘/root/orig_files/hosts’

[root@master ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

[root@master ~]# vim /etc/hosts

[root@master ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

# --
# Openshift hosts
# --
192.168.11.162 master master.ab.lab
192.168.11.163 node1  node1.ab.lab

Test Your "dnsmasq" configurations:
[root@master ~]# reboot 

[root@master ~]# host $(hostname)
master.ab.lab has address 192.168.11.162


[root@master ~]# ping -c1 test.ocp.master.ab.lab
PING test.ocp.master.ab.lab (192.168.11.162) 56(84) bytes of data.
64 bytes from master (192.168.11.162): icmp_seq=1 ttl=64 time=0.026 ms

--- test.ocp.master.ab.lab ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.026/0.026/0.026/0.000 ms


[root@master ~]# ping -c1 google.com
PING google.com (216.58.217.174) 56(84) bytes of data.
64 bytes from iad23s44-in-f14.1e100.net (216.58.217.174): icmp_seq=1 ttl=54 time=14.9 ms

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 14.936/14.936/14.936/0.000 ms


Do the same exact steps with "node1":



Take cold snapshots:

virsh # snapshot-create-as openshift-master 02_dnsmasq --description "After installaing and creating dnsmasq DNS server"
Domain snapshot 02_dnsmasq created

virsh # snapshot-create-as openshift-node1 02_dnsmasq --description "After installaing and creating dnsmasq DNS server"
Domain snapshot 02_dnsmasq created
virsh # snapshot-list openshift-master
 Name                 Creation Time             State
------------------------------------------------------------
 00_fresh_os          2018-07-07 11:47:50 +0200 shutoff
 01_ready_to_install  2018-07-07 12:25:48 +0200 shutoff
 02_dnsmasq           2018-07-08 12:25:15 +0200 shutoff


virsh # snapshot-list openshift-node1
 Name                 Creation Time             State
------------------------------------------------------------
 00_fresh_os          2018-07-07 12:49:20 +0200 shutoff
 01_ready_to_install  2018-07-07 12:55:12 +0200 shutoff
 02_dnsmasq           2018-07-08 12:25:26 +0200 shutoff

0003- OpenShift Lab - Node1

Installation Parameters:


node1.ab.lab
RAM4 GBNetwork192.168.11.0/24
vCPU2IP Address192.168.11.163/24
OS VersionRHEL 7.4DNS192.168.11.1
Hard Disk 140 GBSearch DomainsEMPTY
Hard Disk 240 GBHostnamenode1.ab.lab
KVM Nameopenshift-node1Partitions LayoutAutomatic

[root@base ~]# virsh net-dumpxml openshift
<network connections='2'>
  <name>openshift</name>
  <uuid>883473f1-5db2-489e-89a0-9caf0b04dc6c</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr23' stp='on' delay='0'/>
  <mac address='52:54:00:85:00:9e'/>
  <domain name='openshift'/>
  <ip address='192.168.11.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.11.201' end='192.168.11.210'/>
    </dhcp>
  </ip>
</network>

[root@base ~]# virsh pool-dumpxml OpenShift
<pool type='dir'>
  <name>OpenShift</name>
  <uuid>ce6e6645-9a02-4d9e-b07e-0255cf6e1d54</uuid>
  <capacity unit='bytes'>1082120392704</capacity>
  <allocation unit='bytes'>605260783616</allocation>
  <available unit='bytes'>476859609088</available>
  <source>
  </source>
  <target>
    <path>/VMs/openshift</path>
    <permissions>
      <mode>0755</mode>
      <owner>0</owner>
      <group>0</group>
      <label>unconfined_u:object_r:etc_runtime_t:s0</label>
    </permissions>
  </target>
</pool>

[root@base ~]# virsh vol-info --pool OpenShift node1-hdd1.qcow2
Name:           node1-hdd1.qcow2
Type:           file
Capacity:       40.00 GiB
Allocation:     6.45 MiB
[root@base ~]# virsh vol-info --pool OpenShift node1-hdd2.qcow2
Name:           node1-hdd2.qcow2
Type:           file
Capacity:       40.00 GiB
Allocation:     6.45 MiB


Prepare you subscriptions:

You will need to have evaluation subscription for:
1. Red Hat OpenShift.
2. Red Hat OpenStack that will be used for having Open vSwitch.


Subscribe against Red Hat Subscription Manager:

[root@node1 ~]# subscription-manager register
Registering to: subscription.rhsm.redhat.com:443/subscription
Username: abdurrahman.mohamed
Password: 
The system has been registered with ID: < ID>
[root@node1 ~]# subscription-manager list --available
+-------------------------------------------+
    Available Subscriptions
+-------------------------------------------+
Subscription Name:   60 Day Self-Supported Red Hat OpenStack Platform Preview
Provides:            Red Hat Ceph Storage MON
                     Red Hat Single Sign-On
                     Oracle Java (for RHEL Server)
                     Red Hat CloudForms
                     Red Hat Enterprise MRG Messaging
                     Red Hat Enterprise Linux Atomic Host
                     Red Hat Enterprise Linux High Availability (for RHEL Server)
                     Red Hat Enterprise Linux Load Balancer (for RHEL Server)
                     Red Hat Beta
                     Red Hat Enterprise Linux Fast Datapath Beta
                     Red Hat Ansible Engine
                     Red Hat Enterprise Linux Atomic Host Beta
                     Red Hat Software Collections Beta (for RHEL Server)
                     Red Hat Software Collections (for RHEL Server)
                     Red Hat Ceph Storage
                     Red Hat Enterprise Linux Server
                     Red Hat OpenStack Beta
                     Red Hat OpenStack
SKU:                 SER0406
Contract:            
Pool ID:             <POOL ID1>
Provides Management: No
Available:           Unlimited
Suggested:           1
Service Level:       Self-Support
Service Type:        L1-L3
Subscription Type:   Standard
Ends:                07/22/2018
System Type:         Virtual

Subscription Name:   60 Day Self-Supported Red Hat OpenStack Platform Preview
Provides:            Red Hat Ceph Storage MON
                     Red Hat Single Sign-On
                     Oracle Java (for RHEL Server)
                     Red Hat CloudForms
                     Red Hat Enterprise MRG Messaging
                     Red Hat Enterprise Linux Atomic Host
                     Red Hat Enterprise Linux High Availability (for RHEL Server)
                     Red Hat Enterprise Linux Load Balancer (for RHEL Server)
                     Red Hat Beta
                     Red Hat Enterprise Linux Fast Datapath Beta
                     Red Hat Ansible Engine
                     Red Hat Enterprise Linux Atomic Host Beta
                     Red Hat Software Collections Beta (for RHEL Server)
                     Red Hat Software Collections (for RHEL Server)
                     Red Hat Ceph Storage
                     Red Hat Enterprise Linux Server
                     Red Hat OpenStack Beta
                     Red Hat OpenStack
SKU:                 SER0406
Contract:            
Pool ID:             <POOL ID2>
Provides Management: No
Available:           3
Suggested:           1
Service Level:       Self-Support
Service Type:        L1-L3
Subscription Type:   Standard
Ends:                07/22/2018
System Type:         Physical

Subscription Name:   30 Day Self-Supported Red Hat OpenShift Container Platform, 2-Core Evaluation
Provides:            Red Hat OpenShift Container Platform
                     Red Hat Istio
                     Oracle Java (for RHEL Server) - Extended Update Support
                     Red Hat Enterprise Linux Atomic Host
                     JBoss Enterprise Application Platform
                     Red Hat JBoss AMQ Clients
                     Red Hat Ansible Engine
                     Red Hat OpenShift Enterprise Application Node
                     Red Hat OpenShift Enterprise JBoss FUSE add-on
                     Red Hat Software Collections Beta (for RHEL Server)
                     Red Hat Software Collections (for RHEL Server)
                     Red Hat Enterprise Linux Fast Datapath
                     Red Hat Enterprise Linux Server
                     Red Hat JBoss Core Services
                     Red Hat Gluster Storage Management Console (for RHEL Server)
                     Red Hat OpenShift Enterprise JBoss EAP add-on
                     Oracle Java (for RHEL Server)
                     Red Hat CloudForms Beta
                     Red Hat CloudForms
                     Red Hat OpenShift Enterprise Client Tools
                     Red Hat Storage for Public Cloud (via RHUI)
                     Red Hat Gluster Storage Server for On-premise
                     Red Hat Enterprise Linux High Availability (for RHEL Server)
                     Red Hat OpenShift Enterprise Infrastructure
                     Red Hat Beta
                     Red Hat Enterprise Linux Fast Datapath Beta
                     Red Hat Gluster Storage Nagios Server
                     Red Hat Enterprise Linux Scalable File System (for RHEL Server)
                     Red Hat OpenShift Enterprise JBoss A-MQ add-on
                     JBoss Enterprise Web Server
SKU:                 SER0419
Contract:            11708740
Pool ID:             <POOL ID3>
Provides Management: Yes
Available:           9
Suggested:           0
Service Level:       Self-Support
Service Type:        L1-L3
Subscription Type:   Stackable
Ends:                08/06/2018
System Type:         Physical

[root@node1 ~]# subscription-manager attach --pool=<POOL ID3>
Successfully attached a subscription for: 30 Day Self-Supported Red Hat OpenShift Container Platform, 2-Core Evaluation
[root@node1 ~]# subscription-manager attach --pool=<POOL ID1>
Successfully attached a subscription for: 60 Day Self-Supported Red Hat OpenStack Platform Preview


Install the required Repos:


[root@node1 ~]# subscription-manager repos --disable=*
[root@node1 ~]# subscription-manager repos --enable=rhel-7-server-rpms 
Repository 'rhel-7-server-rpms' is enabled for this system.

[root@node1 ~]# subscription-manager repos --enable=rhel-7-server-optional-rpms 
Repository 'rhel-7-server-optional-rpms' is enabled for this system.

[root@node1 ~]# subscription-manager repos --enable=rhel-7-server-extras-rpms
Repository 'rhel-7-server-extras-rpms' is enabled for this system.

[root@node1 ~]# subscription-manager repos --enable=rhel-7-server-ose-3.5-rpms
Repository 'rhel-7-server-ose-3.5-rpms' is enabled for this system.

[root@node1 ~]# subscription-manager repos --enable=rhel-7-server-openstack-10-rpms
Repository 'rhel-7-server-openstack-10-rpms' is enabled for this system.
[root@node1 ~]# yum repolist
Loaded plugins: product-id, search-disabled-repos, subscription-manager
repo id                                                                                repo name                                                                                    status
rhel-7-server-extras-rpms/x86_64                                                       Red Hat Enterprise Linux 7 Server - Extras (RPMs)                                               875
rhel-7-server-openstack-10-rpms/7Server/x86_64                                         Red Hat OpenStack Platform 10 for RHEL 7 (RPMs)                                               2,052
rhel-7-server-optional-rpms/7Server/x86_64                                             Red Hat Enterprise Linux 7 Server - Optional (RPMs)                                          15,182
rhel-7-server-ose-3.5-rpms/x86_64                                                      Red Hat OpenShift Container Platform 3.5 (RPMs)                                                 695
rhel-7-server-rpms/7Server/x86_64                                                      Red Hat Enterprise Linux 7 Server (RPMs)                                                     20,672
repolist: 39,476


Collect KVM Snapshot:

[root@node1 ~]# poweroff 
[root@base ~]# virsh snapshot-create-as openshift-node1 01_ready_to_install --description "OS with needed subscriptions and repos but before install OpenShift"
Domain snapshot 01_ready_to_install created

0002- OpenShift Lab - master node

Installation Parameters:


master.ab.lab
RAM8 GBNetwork192.168.11.0/24
vCPU2IP Address192.168.11.162/24
OS VersionRHEL 7.4DNS192.168.11.1
Hard Disk 180 GBSearch DomainsEMPTY
Hard Disk 240 GBHostnamemaster.ab.lab
KVM Nameopenshift-masterPartitions LayoutAutomatic


[root@base ~]# virsh net-dumpxml openshift
<network>
  <name>openshift</name>
  <uuid>883473f1-5db2-489e-89a0-9caf0b04dc6c</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr23' stp='on' delay='0'/>
  <mac address='52:54:00:85:00:9e'/>
  <domain name='openshift'/>
  <ip address='192.168.11.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.11.201' end='192.168.11.210'/>
    </dhcp>
  </ip>
</network>

[root@base ~]# virsh pool-dumpxml OpenShift
  <pool type='dir'>
  <name>OpenShift</name>
  <uuid>ce6e6645-9a02-4d9e-b07e-0255cf6e1d54</uuid>
  <capacity unit='bytes'>1082120392704</capacity>
  <allocation unit='bytes'>603432558592</allocation>
  <available unit='bytes'>478687834112</available>
  <source>
  </source>
  <target>
    <path>/VMs/openshift</path>
    <permissions>
      <mode>0755</mode>
      <owner>0</owner>
      <group>0</group>
      <label>unconfined_u:object_r:etc_runtime_t:s0</label>
    </permissions>
  </target>
</pool>

[root@base ~]# virsh vol-info --pool OpenShift master-hdd1.qcow2
Name:           master-hdd1.qcow2
Type:           file
Capacity:       80.00 GiB
Allocation:     12.70 MiB
[root@base ~]# virsh vol-info --pool OpenShift master-hdd2.qcow2
Name:           master-hdd2.qcow2
Type:           file
Capacity:       40.00 GiB
Allocation:     6.45 MiB


Prepare you subscriptions:

You will need to have evaluation subscription for:
1. Red Hat OpenShift.
2. Red Hat OpenStack that will be used for having Open vSwitch.

Subscribe against Red Hat Subscription Manager:

[root@master ~]# subscription-manager register
Registering to: subscription.rhsm.redhat.com:443/subscription
Username: abdurrahman.mohamed
Password: 
The system has been registered with ID: < ID>
[root@master ~]# subscription-manager list --available
+-------------------------------------------+
    Available Subscriptions
+-------------------------------------------+
Subscription Name:   60 Day Self-Supported Red Hat OpenStack Platform Preview
Provides:            Red Hat Ceph Storage MON
                     Red Hat Single Sign-On
                     Oracle Java (for RHEL Server)
                     Red Hat CloudForms
                     Red Hat Enterprise MRG Messaging
                     Red Hat Enterprise Linux Atomic Host
                     Red Hat Enterprise Linux High Availability (for RHEL Server)
                     Red Hat Enterprise Linux Load Balancer (for RHEL Server)
                     Red Hat Beta
                     Red Hat Enterprise Linux Fast Datapath Beta
                     Red Hat Ansible Engine
                     Red Hat Enterprise Linux Atomic Host Beta
                     Red Hat Software Collections Beta (for RHEL Server)
                     Red Hat Software Collections (for RHEL Server)
                     Red Hat Ceph Storage
                     Red Hat Enterprise Linux Server
                     Red Hat OpenStack Beta
                     Red Hat OpenStack
SKU:                 SER0406
Contract:            
Pool ID:             <POOL ID1>
Provides Management: No
Available:           Unlimited
Suggested:           1
Service Level:       Self-Support
Service Type:        L1-L3
Subscription Type:   Standard
Ends:                07/22/2018
System Type:         Virtual

Subscription Name:   60 Day Self-Supported Red Hat OpenStack Platform Preview
Provides:            Red Hat Ceph Storage MON
                     Red Hat Single Sign-On
                     Oracle Java (for RHEL Server)
                     Red Hat CloudForms
                     Red Hat Enterprise MRG Messaging
                     Red Hat Enterprise Linux Atomic Host
                     Red Hat Enterprise Linux High Availability (for RHEL Server)
                     Red Hat Enterprise Linux Load Balancer (for RHEL Server)
                     Red Hat Beta
                     Red Hat Enterprise Linux Fast Datapath Beta
                     Red Hat Ansible Engine
                     Red Hat Enterprise Linux Atomic Host Beta
                     Red Hat Software Collections Beta (for RHEL Server)
                     Red Hat Software Collections (for RHEL Server)
                     Red Hat Ceph Storage
                     Red Hat Enterprise Linux Server
                     Red Hat OpenStack Beta
                     Red Hat OpenStack
SKU:                 SER0406
Contract:            
Pool ID:             <POOL ID2>
Provides Management: No
Available:           3
Suggested:           1
Service Level:       Self-Support
Service Type:        L1-L3
Subscription Type:   Standard
Ends:                07/22/2018
System Type:         Physical

Subscription Name:   30 Day Self-Supported Red Hat OpenShift Container Platform, 2-Core Evaluation
Provides:            Red Hat OpenShift Container Platform
                     Red Hat Istio
                     Oracle Java (for RHEL Server) - Extended Update Support
                     Red Hat Enterprise Linux Atomic Host
                     JBoss Enterprise Application Platform
                     Red Hat JBoss AMQ Clients
                     Red Hat Ansible Engine
                     Red Hat OpenShift Enterprise Application Node
                     Red Hat OpenShift Enterprise JBoss FUSE add-on
                     Red Hat Software Collections Beta (for RHEL Server)
                     Red Hat Software Collections (for RHEL Server)
                     Red Hat Enterprise Linux Fast Datapath
                     Red Hat Enterprise Linux Server
                     Red Hat JBoss Core Services
                     Red Hat Gluster Storage Management Console (for RHEL Server)
                     Red Hat OpenShift Enterprise JBoss EAP add-on
                     Oracle Java (for RHEL Server)
                     Red Hat CloudForms Beta
                     Red Hat CloudForms
                     Red Hat OpenShift Enterprise Client Tools
                     Red Hat Storage for Public Cloud (via RHUI)
                     Red Hat Gluster Storage Server for On-premise
                     Red Hat Enterprise Linux High Availability (for RHEL Server)
                     Red Hat OpenShift Enterprise Infrastructure
                     Red Hat Beta
                     Red Hat Enterprise Linux Fast Datapath Beta
                     Red Hat Gluster Storage Nagios Server
                     Red Hat Enterprise Linux Scalable File System (for RHEL Server)
                     Red Hat OpenShift Enterprise JBoss A-MQ add-on
                     JBoss Enterprise Web Server
SKU:                 SER0419
Contract:            11708740
Pool ID:             <POOL ID3>
Provides Management: Yes
Available:           9
Suggested:           0
Service Level:       Self-Support
Service Type:        L1-L3
Subscription Type:   Stackable
Ends:                08/06/2018
System Type:         Physical

[root@master ~]# subscription-manager attach --pool=<POOL ID3>
Successfully attached a subscription for: 30 Day Self-Supported Red Hat OpenShift Container Platform, 2-Core Evaluation
[root@master ~]# subscription-manager attach --pool=<POOL ID1>
Successfully attached a subscription for: 60 Day Self-Supported Red Hat OpenStack Platform Preview


Install the required Repos:


[root@master ~]# subscription-manager repos --disable=*
[root@master ~]# subscription-manager repos --enable=rhel-7-server-rpms 
Repository 'rhel-7-server-rpms' is enabled for this system.

[root@master ~]# subscription-manager repos --enable=rhel-7-server-optional-rpms 
Repository 'rhel-7-server-optional-rpms' is enabled for this system.

[root@master ~]# subscription-manager repos --enable=rhel-7-server-extras-rpms
Repository 'rhel-7-server-extras-rpms' is enabled for this system.

[root@master ~]# subscription-manager repos --enable=rhel-7-server-ose-3.5-rpms
Repository 'rhel-7-server-ose-3.5-rpms' is enabled for this system.

[root@master ~]# subscription-manager repos --enable=rhel-7-server-openstack-10-rpms
Repository 'rhel-7-server-openstack-10-rpms' is enabled for this system.
[root@master ~]# yum repolist
Loaded plugins: product-id, search-disabled-repos, subscription-manager
repo id                                                                                repo name                                                                                    status
rhel-7-server-extras-rpms/x86_64                                                       Red Hat Enterprise Linux 7 Server - Extras (RPMs)                                               875
rhel-7-server-openstack-10-rpms/7Server/x86_64                                         Red Hat OpenStack Platform 10 for RHEL 7 (RPMs)                                               2,052
rhel-7-server-optional-rpms/7Server/x86_64                                             Red Hat Enterprise Linux 7 Server - Optional (RPMs)                                          15,182
rhel-7-server-ose-3.5-rpms/x86_64                                                      Red Hat OpenShift Container Platform 3.5 (RPMs)                                                 695
rhel-7-server-rpms/7Server/x86_64                                                      Red Hat Enterprise Linux 7 Server (RPMs)                                                     20,672
repolist: 39,476


Collect KVM Snapshot:

[root@master ~]# poweroff 
[root@base ~]# virsh snapshot-create-as openshift-master 01_ready_to_install --description "OS with needed subscriptions and repos but before install OpenShift"
Domain snapshot 01_ready_to_install created

0001 - OpenShift Overview

Introduction:












Architecture:










Thursday, 5 July 2018

006- Docker Lab



[ab@fedora28 ~]$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
1608b8958761        mariadb             "docker-entrypoint.s…"   17 minutes ago      Up 17 minutes       3306/tcp            mariadb
[ab@fedora28 ~]$ docker search nginx
NAME                                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
nginx                                                  Official build of Nginx.                        8946                [OK]                
[ab@fedora28 ~]$ docker pull nginx
[ab@fedora28 ~]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mariadb             latest              520fc647a087        42 hours ago        403MB
nginx               latest              649dcb69b782        47 hours ago        109MB
httpd               latest              2a7d646dbba8        8 days ago          178MB
centos              latest              49f7960eb7e4        4 weeks ago         200MB
fedora              latest              cc510acfcd70        2 months ago        253MB
[ab@fedora28 ~]$ docker run -dit --name nginx -p 8088:80 nginx /bin/bash
5585c42822f1b7618ea5a0934759d2b1828390b32d65dbc34942e5990422cf1d
[ab@fedora28 ~]$ docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
5585c42822f1        nginx               "/bin/bash"              22 seconds ago      Up 20 seconds       0.0.0.0:8088->80/tcp   nginx
1608b8958761        mariadb             "docker-entrypoint.s…"   22 minutes ago      Up 22 minutes       3306/tcp               mariadb
[ab@fedora28 ~]$ sudo netstat -tupenl | grep 8088
tcp6       0      0 :::8088                 :::*                    LISTEN      0          92161      9692/docker-proxy   
[ab@fedora28 ~]$ docker attach nginx


005- Docker Storage

Introduction:




Create "mariadb" container and mount "/var/lib/mysql" dir in the "container" to be "/var/local/mysql" dir in the "host":

[ab@fedora28 ~]$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@fedora28 ~]# hostname
fedora28.ab.lab

[root@fedora28 ~]# id
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

[root@fedora28 ~]# mkdir -v /var/local/mysql
mkdir: created directory '/var/local/mysql'

[root@fedora28 ~]# setenforce 0

[root@fedora28 ~]# chown -vR 27:27 /var/local/mysql/                        <--- MYSQL UID/GID == 27
changed ownership of '/var/local/mysql/' from root:root to 27:27
[ab@fedora28 ~]$ docker search mariadb
NAME                                                      DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
mariadb                                                   MariaDB is a community-developed fork of MyS…   2048                [OK]                
[ab@fedora28 ~]$ docker pull mariadb
[ab@fedora28 ~]$ docker help run | grep -e "\-v," -e "-e," 
  -v, --volume list                    Bind mount a volume
  -e, --env list                       Set environment variables
[ab@fedora28 ~]$ docker run --name mariadb -d -v /var/local/mysql:/var/lib/mysql -e MYSQL_USER=user -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=addresses -e MYSQL_ROOT_PASSWORD=password mariadb
1608b89587613e59b001c60324e329c151d55e39a73fcaf5903f99be326d39de
[ab@fedora28 ~]$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
1608b8958761        mariadb             "docker-entrypoint.s…"   23 seconds ago      Up 22 seconds       3306/tcp            mariadb

[root@fedora28 ~]# ls /var/local/mysql/
addresses  aria_log.00000001  aria_log_control  ib_buffer_pool  ibdata1  ib_logfile0  ib_logfile1  ibtmp1  multi-master.info  mysql  performance_schema  tc.log
[ab@fedora28 ~]$ docker exec -it mariadb /bin/bash
root@1608b8958761:/# ls /var/lib/mysql/
addresses  aria_log.00000001  aria_log_control ib_buffer_pool ib_logfile0  ib_logfile1  ibdata1  ibtmp1  multi-master.info  mysql  performance_schema  tc.log

root@1608b8958761:/# mysql -u user -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 10.3.8-MariaDB-1:10.3.8+maria~jessie mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| addresses          |
| information_schema |
+--------------------+
2 rows in set (0.001 sec)

MariaDB [(none)]> Bye

004- Docker Networking

Architecture


B --> Bridge.
Blue Square s Docket Host.

Summary:



Docker Port Mapping


Create container named "httpd" which is using "httpd" image and forward "container" port 80 to "host" port 8080:
[ab@fedora28 ~]$ docker search httpd
NAME                                    DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
httpd                                   The Apache HTTP Server Project                  1799                [OK]                
[ab@fedora28 ~]$ docker run -d --name httpd -p 8080:80 httpd

Access "httpd" container from the docker host:
[ab@fedora28 ~]$ docker ps
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS                  NAMES
b2ae9a8c521f        httpd               "httpd-foreground"   13 seconds ago      Up 8 seconds        0.0.0.0:8080->80/tcp   httpd
[ab@fedora28 ~]$ sudo netstat -tupenl | grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN      0          29647      1225/docker-proxy   
[ab@fedora28 ~]$ lynx --dump http://localhost:8080
                                   It works!

Access "httpd" container:
[ab@fedora28 ~]$ docker exec -it httpd /bin/bash

root@b2ae9a8c521f:/usr/local/apache2# cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
NAME="Debian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
Access "httpd" container:

root@b2ae9a8c521f:/usr/local/apache2# apt-get update root@b2ae9a8c521f:/usr/local/apache2# apt-get install lynx root@b2ae9a8c521f:/usr/local/apache2# lynx --dump localhost It works!

003- Daily Operational Containers Management

Creating and removing "wordpress" container:

[ab@fedora28 ~]$ docker search wordpress
NAME                                                DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
wordpress                                           The WordPress rich content management system…   2367                [OK]                
[...]
[ab@fedora28 ~]$ docker pull wordpress
[ab@fedora28 ~]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
wordpress           latest              1d3cc82944da        7 days ago          408MB
fedora              latest              cc510acfcd70        2 months ago        253MB
[ab@fedora28 ~]$ docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[ab@fedora28 ~]$ docker pull wordpress
[ab@fedora28 ~]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
wordpress           latest              1d3cc82944da        7 days ago          408MB
fedora              latest              cc510acfcd70        2 months ago        253MB
[ab@fedora28 ~]$ docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[ab@fedora28 ~]$ docker run -it wordpress /bin/bash

root@db9ed3a7383e:/var/www/html# hostname 
db9ed3a7383e

root@db9ed3a7383e:/var/www/html# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 9.4 (stretch)
Release: 9.4
Codename: stretch

root@db9ed3a7383e:/var/www/html# +
[ab@fedora28 ~]$ docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
db9ed3a7383e        wordpress           "docker-entrypoint.s…"   3 minutes ago       Up 3 minutes        80/tcp              condescending_bartik

[ab@fedora28 ~]$ docker stop db9ed3a7383e
db9ed3a7383e
[ab@fedora28 ~]$ docker rm db9ed3a7383e
db9ed3a7383e
[ab@fedora28 ~]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
wordpress           latest              1d3cc82944da        7 days ago          408MB
fedora              latest              cc510acfcd70        2 months ago        253MB
[ab@fedora28 ~]$ docker rmi wordpress
[ab@fedora28 ~]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
fedora              latest              cc510acfcd70        2 months ago        253MB


Create new CentOS container with name "centos" and hostname "centos":

[ab@fedora28 ~]$ docker search centos
NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
centos                             The official build of CentOS.                   4419                [OK]                
[...]
[ab@fedora28 ~]$ docker pull centos
[ab@fedora28 ~]$ docker help run | grep -e "\-d," -e "--name" -e "--hostname"
  -d, --detach                         Run container in background and print container ID
  -h, --hostname string                Container host name
      --name string                    Assign a name to the container
[ab@fedora28 ~]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              49f7960eb7e4        4 weeks ago         200MB
fedora              latest              cc510acfcd70        2 months ago        253MB
[ab@fedora28 ~]$ docker run -dit --name centos --hostname=centos centos /bin/bash
5d3c83663ab9cf814ebece52285a83f18f769ba5f0f3745bb16f9e2d4abe77e9
[ab@fedora28 ~]$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
5d3c83663ab9        centos              "/bin/bash"         11 seconds ago      Up 10 seconds                           centos
[ab@fedora28 ~]$ docker attach centos
[root@centos /]# hostname
centos
[root@centos /]# top
top - 14:00:56 up  2:17,  0 users,  load average: 0.02, 0.04, 0.03
Tasks:   2 total,   1 running,   1 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  4038808 total,  2695736 free,   214452 used,  1128620 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.  3500692 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                                                       
    1 root      20   0   11832   3020   2620 S  0.0  0.1   0:00.03 bash                                                                                          
   15 root      20   0   56172   3896   3364 R  0.0  0.1   0:00.00 top   
[root@centos /]# exit
exit
[ab@fedora28 ~]$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[ab@fedora28 ~]$ docker ps -a
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS                      PORTS               NAMES
5d3c83663ab9        centos              "/bin/bash"          3 minutes ago       Exited (0) 5 seconds ago                        centos
3ed4e70d4c73        fedora              "/bin/bash"          About an hour ago   Exited (0) 25 minutes ago                       competent_villani
901f42ca4f10        fedora              "echo hello world"   2 hours ago         Exited (0) 2 hours ago                          eloquent_elbakyan


How docker-engine deals with 'docker run' command? It will create new container:


Three Containers:
[ab@fedora28 ~]$ docker ps -a
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS                      PORTS               NAMES
5d3c83663ab9        centos              "/bin/bash"          3 minutes ago       Exited (0) 5 seconds ago                        centos
3ed4e70d4c73        fedora              "/bin/bash"          About an hour ago   Exited (0) 25 minutes ago                       competent_villani
901f42ca4f10        fedora              "echo hello world"   2 hours ago         Exited (0) 2 hours ago                          eloquent_elbakyan

Now, four containers, the new one name is "modest_montalcini"
[ab@fedora28 ~]$ docker run centos /usr/bin/free -m 
              total        used        free      shared  buff/cache   available
Mem:           3944         197        2643           0        1102        3430
Swap:          2047           0        2047
[ab@fedora28 ~]$ docker ps -as
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS                      PORTS               NAMES               SIZE
e7ec9ef2443f        centos              "/usr/bin/free -m"   5 minutes ago       Exited (0) 5 minutes ago                        modest_montalcini   0B (virtual 200MB)       <----
5d3c83663ab9        centos              "/bin/bash"          15 minutes ago      Exited (0) 11 minutes ago                       centos              23B (virtual 200MB)
3ed4e70d4c73        fedora              "/bin/bash"          2 hours ago         Exited (0) 37 minutes ago                       competent_villani   76B (virtual 253MB)
901f42ca4f10        fedora              "echo hello world"   2 hours ago         Exited (0) 2 hours ago                          eloquent_elbakyan   0B (virtual 253MB)


Relation between docker "host" PID and docker "container"


Start "centos" container again:
[ab@fedora28 ~]$ docker ps -as
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS                        PORTS               NAMES               SIZE
e7ec9ef2443f        centos              "/usr/bin/free -m"   9 minutes ago       Exited (0) 9 minutes ago                          modest_montalcini   0B (virtual 200MB)
5d3c83663ab9        centos              "/bin/bash"          19 minutes ago      Exited (137) 14 seconds ago                       centos              23B (virtual 200MB)
3ed4e70d4c73        fedora              "/bin/bash"          2 hours ago         Exited (0) 40 minutes ago                         competent_villani   76B (virtual 253MB)
901f42ca4f10        fedora              "echo hello world"   2 hours ago         Exited (0) 2 hours ago                            eloquent_elbakyan   0B (virtual 253MB)
[ab@fedora28 ~]$ docker start centos
centos
[ab@fedora28 ~]$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
5d3c83663ab9        centos              "/bin/bash"         19 minutes ago      Up 6 seconds                            centos

From the docker "host" check the running PIDs in "centos" container:

[ab@fedora28 ~]$ docker help top

Usage: docker top CONTAINER [ps OPTIONS]

Display the running processes of a container

Options:
[ab@fedora28 ~]$ docker top centos
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                5073                5058                0                   16:18               pts/0               00:00:00            /bin/bash
[ab@fedora28 ~]$ hostname
fedora28.ab.lab
[ab@fedora28 ~]$ ps -ef | grep 5058
root      5058  2344  0 16:18 ?        00:00:00 docker-containerd-shim -namespace moby -workdir /var/lib/docker/containerd/daemon/io.containerd.runtime.v1.linux/moby/5d3c83663ab9cf814ebece52285a83f18f769ba5f0f3745bb16f9e2d4abe77e9 -address /var/run/docker/containerd/docker-containerd.sock -containerd-binary /usr/bin/docker-containerd -runtime-root /var/run/docker/runtime-runc
root      5073  5058  0 16:18 pts/0    00:00:00 /bin/bash


Checking containers status:

[ab@fedora28 ~]$ docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
5d3c83663ab9        centos              "/bin/bash"         27 minutes ago      Up 8 minutes                            centos
[ab@fedora28 ~]$ docker help stats

Usage: docker stats [OPTIONS] [CONTAINER...]

Display a live stream of container(s) resource usage statistics

Options:
  -a, --all             Show all containers (default shows just running)
      --format string   Pretty-print images using a Go template
      --no-stream       Disable streaming stats and only pull the first result
      --no-trunc        Do not truncate output
[ab@fedora28 ~]$ docker stats --no-stream
CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT   MEM %               NET I/O             BLOCK I/O           PIDS
5d3c83663ab9        centos              0.00%               884KiB / 3.852GiB   0.02%               1.12kB / 0B         0B / 0B             1
[ab@fedora28 ~]$ docker stats --no-stream --all
CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT   MEM %               NET I/O             BLOCK I/O           PIDS
e7ec9ef2443f        modest_montalcini   0.00%               0B / 0B             0.00%               0B / 0B             0B / 0B             0
5d3c83663ab9        centos              0.00%               884KiB / 3.852GiB   0.02%               1.12kB / 0B         0B / 0B             1
3ed4e70d4c73        competent_villani   0.00%               0B / 0B             0.00%               0B / 0B             0B / 0B             0
901f42ca4f10        eloquent_elbakyan   0.00%               0B / 0B             0.00%               0B / 0B             0B / 0B             0


Copy files from docker "host" to specific container and visa vers:

[ab@fedora28 ~]$ hostname
fedora28.ab.lab
[ab@fedora28 ~]$ docker help cp

Usage: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
 docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH

Copy files/folders between a container and the local filesystem

Options:
  -a, --archive       Archive mode (copy all uid/gid information)
  -L, --follow-link   Always follow symbol link in SRC_PATH
[ab@fedora28 ~]$ docker help cp

Usage: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
 docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH

Copy files/folders between a container and the local filesystem

Options:
  -a, --archive       Archive mode (copy all uid/gid information)
  -L, --follow-link   Always follow symbol link in SRC_PATH

"centos" container -> docker "host":
[ab@fedora28 ~]$ docker cp centos:/etc/passwd /tmp/centos-container-password
[ab@fedora28 ~]$ head -n1 /tmp/centos-container-password 
root:x:0:0:root:/root:/bin/bash

container "host" -> "centos" container:
[ab@fedora28 ~]$ docker cp /tmp/centos-container-password centos:/root/passwd
[ab@fedora28 ~]$ docker exec centos head -n1 /root/passwd
root:x:0:0:root:/root:/bin/bash


Understanding how Processes are listed inside the container:


Create new container "demo1" and start it by "dd if=/dev/zero of=/dev/null" command. This will be infinite process:
[ab@fedora28 ~]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              49f7960eb7e4        4 weeks ago         200MB
fedora              latest              cc510acfcd70        2 months ago        253MB
[ab@fedora28 ~]$ hostname
fedora28.ab.lab
[ab@fedora28 ~]$ docker run --name demo1 centos dd if=/dev/zero of=/dev/null

Check running PID for 'demo1' container in the 'host':
[ab@fedora28 ~]$ docker top demo1
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                6338                6323                95                  19:56               ?                   00:00:21            dd if=/dev/zero of=/dev/null
[ab@fedora28 ~]$ ps -ef | grep 6338
[ab@fedora28 ~]$ ps -ef | grep 6338 | grep -v grep
root      6338  6323 98 19:56 ?        00:01:08 dd if=/dev/zero of=/dev/null
[ab@fedora28 ~]$ ps -ef | grep 6323 | grep -v grep
root      6323  2344  0 19:56 ?        00:00:00 docker-containerd-shim -namespace moby -workdir /var/lib/docker/containerd/daemon/io.containerd.runtime.v1.linux/moby/e8324cfcdc0ffea78d754a764fcfc7b38e1308e0913196e1e772456d4727d538 -address /var/run/docker/containerd/docker-containerd.sock -containerd-binary /usr/bin/docker-containerd -runtime-root /var/run/docker/runtime-runc
root      6338  6323 99 19:56 ?        00:01:43 dd if=/dev/zero of=/dev/null

Try to execute "/bin/bash" inside "demo1" container to be able to access the container, then check the process. PID 1 is "dd" and PID 9 is "bash":

[ab@fedora28 ~]$ docker exec -it demo1 /bin/bash
[root@e8324cfcdc0f /]# top

top - 17:59:15 up  6:15,  0 users,  load average: 0.99, 0.85, 0.59
Tasks:   3 total,   2 running,   1 sleeping,   0 stopped,   0 zombie
%Cpu(s): 47.8 us, 51.8 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.3 hi,  0.0 si,  0.0 st
KiB Mem :  4038808 total,  2684956 free,   212964 used,  1140888 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.  3497668 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                                                       
    1 root      20   0    4416    768    696 R 99.3  0.0   3:08.56 dd                                                                                            
    9 root      20   0   11832   3028   2676 S  0.0  0.1   0:00.01 bash                                                                                          
   22 root      20   0   56140   3864   3368 R  0.0  0.1   0:00.00 top    


Inspect Container Parameters:

[ab@fedora28 ~]$ docker help inspect 

Usage: docker inspect [OPTIONS] NAME|ID [NAME|ID...]

Return low-level information on Docker objects

Options:
  -f, --format string   Format the output using the given Go template
  -s, --size            Display total file sizes if the type is container
      --type string     Return JSON for specified type
[ab@fedora28 ~]$ docker inspect centos
[ab@fedora28 ~]$ docker inspect -f '{{ .NetworkSettings.IPAddress }}' centos
172.17.0.2