Category Archives: RHEL Atomic Host

How to link containers in RHEL Atomic ?

In this article I am going to link two containers. It will help to provide connectivity between the containers. I would suggest you to refer the link to know more about linking container.

Step 1 : I have run the new container using below command port 8080 is exposed to host port 8080.

-bash-4.2# docker run –name job1 -p 8080:8080 -it rhel

We can verify the same using below.

-bash-4.2# docker port job1
8080/tcp -> 0.0.0.0:8080

Step 2 : Check the status of docker and networking configuration from host.

-bash-4.2# docker ps
CONTAINER ID        IMAGE                                   COMMAND             CREATED             STATUS              PORTS                    NAMES
de3bdc15e436        registry.access.redhat.com/rhel:7.1-4   “/usr/bin/bash”     2 minutes ago       Up 2 minutes        0.0.0.0:8080->8080/tcp   job1

After starting the container ip address is showing in output bridge to which docker interfaces will be connected.

-bash-4.2# ifconfig -a
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 172.17.42.1  netmask 255.255.0.0  broadcast 0.0.0.0
inet6 fe80::5484:7aff:fefe:9799  prefixlen 64  scopeid 0x20<link>
ether 56:84:7a:fe:97:99  txqueuelen 0  (Ethernet)
RX packets 7  bytes 460 (460.0 B)
RX errors 0  dropped 0  overruns 0  frame 0
TX packets 16  bytes 2018 (1.9 KiB)
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

In iptables as well we can see the new rule has been added in FORWARD chain.

-bash-4.2# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  —  anywhere             172.17.0.2           tcp dpt:webcache
ACCEPT     all  —  anywhere             anywhere             ctstate RELATED,ESTABLISHED
ACCEPT     all  —  anywhere             anywhere
ACCEPT     all  —  anywhere             anywhere

Step 3 : Lets start another container(job2) by linking to already running container (job1).

-bash-4.2# docker run –name job2 –link job1:job1 -it rhel

Inside that container we can check the environment information and we will find the settings for job1 container these are for communication between the containers.

[root@62609febed2b /]# printenv | grep -i job1
JOB1_PORT=tcp://172.17.0.2:8080
JOB1_PORT_8080_TCP_PORT=8080
JOB1_PORT_8080_TCP=tcp://172.17.0.2:8080
JOB1_NAME=/job2/job1
JOB1_ENV_container=docker
JOB1_PORT_8080_TCP_PROTO=tcp
JOB1_PORT_8080_TCP_ADDR=172.17.0.2

We can also find the entry added in output of /etc/hosts.

[root@62609febed2b /]# cat /etc/hosts | grep -i job1
172.17.0.2      job1

Step 4 : We can see the new rule has been added for container job2 in host iptables.

-bash-4.2# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  —  172.17.0.2           172.17.0.3           tcp spt:webcache
ACCEPT     tcp  —  172.17.0.3           172.17.0.2           tcp dpt:webcache
ACCEPT     tcp  —  anywhere             172.17.0.2           tcp dpt:webcache
ACCEPT     all  —  anywhere             anywhere             ctstate RELATED,ESTABLISHED
ACCEPT     all  —  anywhere             anywhere
ACCEPT     all  —  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

As we are not exposing any port hence nothing is shown in below output.

-bash-4.2# docker port job2

Check the output of bridge to see the interfaces of docker which are connected to bridge.

-bash-4.2# brctl show
bridge name     bridge id               STP enabled     interfaces
docker0         8000.56847afe9799       no              veth953e475
vetha66139a

Step 5 : As I was testing this inside Atomic RHEL host, containers were not having ping command hence to verify the work I have followed the below workaround to make the ping command work inside the container.

Installed iputils.x86_64 0:20121221-6.el7 package.

[root@62609febed2b /]# mkdir -p /opt/ping
[root@62609febed2b /]# cp /usr/bin/ping /opt/ping/
[root@62609febed2b /]# /opt/ping/ping job1
PING job1 (172.17.0.2) 56(84) bytes of data.
64 bytes from job1 (172.17.0.2): icmp_seq=1 ttl=64 time=0.300 ms
64 bytes from job1 (172.17.0.2): icmp_seq=2 ttl=64 time=0.076 ms

How to use dockerfiles to create container ?

In this article I am going to show how to create image from the dockerfile. A dockerfile is a text document that contains all the commands you would normally execute manually in order to build a Docker image.

Step 1 : I have created docker file in one a directory test2.

-bash-4.2# pwd
/root/test2

-bash-4.2# cat Dockerfile
## Setting environment and working directory
FROM rhel
MAINTAINER vickygup1
RUN yum update -y
RUN yum install httpd -y
RUN yum clean all
WORKDIR /tmp
ENV Hello version1

You may refer the article to know more about the syntax of Dockerfile.

Step 2 : Bit explanation on my dockerfile. I am going to install the httpd package and change my working directory to /tmp and adding one environment variable. Dockerfile help us to avoid issuing the command everytime while running container.

Step 3 : From the dockerfile I am going to create one image and using that image I will run container.

-bash-4.2# docker build -t local/demo1:tag1 .
Sending build context to Docker daemon  2.56 kB
Sending build context to Docker daemon
Step 0 : FROM rhel
—> 10acc31def5d
Step 1 : MAINTAINER vickygup1
—> Running in fc8ae3eed0e4
—> 586f56caa630
Removing intermediate container fc8ae3eed0e4
Step 2 : RUN yum update -y
—> Running in bafdd145ba46
Loaded plugins: product-id, subscription-manager
https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/os/repodata/bacb8858a00f81e427cee86b6714f411a78fb4b0-comps-rhel-x86_64-server-7.                       xml.gz: [Errno 14] curl#6 – “Could not resolve host: cdn.redhat.com; Name or service not known”
Trying other mirror.
https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/os/repodata/94782eadb60f106000b4038fcd69b72026903d2ad8fe64bfb39c63c87f8bd706-upd                       ateinfo.xml.gz: [Errno 14] curl#6 – “Could not resolve host: cdn.redhat.com; Name or service not known”
Trying other mirror.
Resolving Dependencies
–> Running transaction check
—> Package subscription-manager.x86_64 0:1.13.19-1.el7 will be updated
—> Package subscription-manager.x86_64 0:1.13.22-1.el7 will be an update
—> Package tzdata.noarch 0:2014j-1.el7 will be updated
—> Package tzdata.noarch 0:2015a-1.el7 will be an update
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package                 Arch      Version          Repository             Size
================================================================================
Updating:
subscription-manager    x86_64    1.13.22-1.el7    rhel-7-server-rpms    795 k
tzdata                  noarch    2015a-1.el7      rhel-7-server-rpms    432 k

Transaction Summary
================================================================================
Upgrade  2 Packages

Total download size: 1.2 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
warning: /var/cache/yum/x86_64/7Server/rhel-7-server-rpms/packages/tzdata-2015a-1.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51                       : NOKEY
Public key for tzdata-2015a-1.el7.noarch.rpm is not installed
——————————————————————————–
Total                                              138 kB/s | 1.2 MB  00:08
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Importing GPG key 0xFD431D51:
Userid     : “Red Hat, Inc. (release key 2) <security@redhat.com>”
Fingerprint: 567e 347a d004 4ade 55ba 8a5f 199e 2f91 fd43 1d51
Package    : redhat-release-server-7.1-1.el7.x86_64 (@koji-override-0/7.0)
From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Importing GPG key 0x2FA658E0:
Userid     : “Red Hat, Inc. (auxiliary key) <security@redhat.com>”
Fingerprint: 43a6 e49c 4a38 f4be 9abf 2a53 4568 9c88 2fa6 58e0
Package    : redhat-release-server-7.1-1.el7.x86_64 (@koji-override-0/7.0)
From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating   : tzdata-2015a-1.el7.noarch                                    1/4
Updating   : subscription-manager-1.13.22-1.el7.x86_64                    2/4
Cleanup    : tzdata-2014j-1.el7.noarch                                    3/4
Cleanup    : subscription-manager-1.13.19-1.el7.x86_64                    4/4
Verifying  : subscription-manager-1.13.22-1.el7.x86_64                    1/4
Verifying  : tzdata-2015a-1.el7.noarch                                    2/4
Verifying  : tzdata-2014j-1.el7.noarch                                    3/4
Verifying  : subscription-manager-1.13.19-1.el7.x86_64                    4/4

Updated:
subscription-manager.x86_64 0:1.13.22-1.el7    tzdata.noarch 0:2015a-1.el7

Complete!
—> 9ffa51ca1d70
Removing intermediate container bafdd145ba46
Step 3 : RUN yum install httpd -y
—> Running in ea50ad41458f
Loaded plugins: product-id, subscription-manager
Resolving Dependencies
–> Running transaction check
—> Package httpd.x86_64 0:2.4.6-31.el7 will be installed
–> Processing Dependency: httpd-tools = 2.4.6-31.el7 for package: httpd-2.4.6-31.el7.x86_64
–> Processing Dependency: system-logos >= 7.92.1-1 for package: httpd-2.4.6-31.el7.x86_64
–> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-31.el7.x86_64
–> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-31.el7.x86_64
–> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-31.el7.x86_64
–> Running transaction check
—> Package apr.x86_64 0:1.4.8-3.el7 will be installed
—> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
—> Package httpd-tools.x86_64 0:2.4.6-31.el7 will be installed
—> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
—> Package redhat-logos.noarch 0:70.0.3-4.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package           Arch        Version            Repository               Size
================================================================================
Installing:
httpd             x86_64      2.4.6-31.el7       rhel-7-server-rpms      1.2 M
Installing for dependencies:
apr               x86_64      1.4.8-3.el7        rhel-7-server-rpms      103 k
apr-util          x86_64      1.5.2-6.el7        rhel-7-server-rpms       92 k
httpd-tools       x86_64      2.4.6-31.el7       rhel-7-server-rpms       79 k
mailcap           noarch      2.1.41-2.el7       rhel-7-server-rpms       31 k
redhat-logos      noarch      70.0.3-4.el7       rhel-7-server-rpms       13 M

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

Total download size: 14 M
Installed size: 18 M
Downloading packages:
——————————————————————————–
Total                                               68 kB/s |  14 MB  03:35
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7.x86_64                                       1/6
Installing : apr-util-1.5.2-6.el7.x86_64                                  2/6
Installing : httpd-tools-2.4.6-31.el7.x86_64                              3/6
Installing : mailcap-2.1.41-2.el7.noarch                                  4/6
Installing : redhat-logos-70.0.3-4.el7.noarch                             5/6
Installing : httpd-2.4.6-31.el7.x86_64                                    6/6
Verifying  : redhat-logos-70.0.3-4.el7.noarch                             1/6
Verifying  : apr-1.4.8-3.el7.x86_64                                       2/6
Verifying  : mailcap-2.1.41-2.el7.noarch                                  3/6
Verifying  : httpd-2.4.6-31.el7.x86_64                                    4/6
Verifying  : apr-util-1.5.2-6.el7.x86_64                                  5/6
Verifying  : httpd-tools-2.4.6-31.el7.x86_64                              6/6

Installed:
httpd.x86_64 0:2.4.6-31.el7

Dependency Installed:
apr.x86_64 0:1.4.8-3.el7                  apr-util.x86_64 0:1.5.2-6.el7
httpd-tools.x86_64 0:2.4.6-31.el7         mailcap.noarch 0:2.1.41-2.el7
redhat-logos.noarch 0:70.0.3-4.el7

Complete!
—> 0aab5f0659d3
Removing intermediate container ea50ad41458f
Step 4 : RUN yum clean all
—> Running in 1d8a1b55646c
Loaded plugins: product-id, subscription-manager
Cleaning repos: rhel-7-server-rpms
Cleaning up everything
—> 168a1a10c352
Removing intermediate container 1d8a1b55646c
Step 5 : WORKDIR /tmp
—> Running in 9d84d8cc5a6c
—> 6c871aee9223
Removing intermediate container 9d84d8cc5a6c
Step 6 : ENV Hello version1
—> Running in a7f0817d03a0
—> 4a16ef98360b
Removing intermediate container a7f0817d03a0
Successfully built 4a16ef98360b

Step 4 : Image has been built successfully we can verify the same by issuing below command.

-bash-4.2# docker images
REPOSITORY                        TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
local/demo1                       tag1                4a16ef98360b        2 minutes ago       270.8 MB

Step 5 : Run the container using image created in step 3 and verify that everything is according to the configuration file.

-bash-4.2# docker run -ti –name check1 4a16ef98360b
[root@a85d0a125bf9 tmp]# pwd
/tmp

In configuration file we have given /tmp as default dir.

We have set one environment variable as well we can check that also.

[root@a85d0a125bf9 tmp]# echo $Hello
version1

How to upgrade Redhat Atomic Host ?

In this article I am going to show how to upgrade the RHEL Atomic Host.

Step 1 : I have installed the RHEL Atomic host on VMware workstation.

Step 2 : Checked the current version using below commands.

-bash-4.2# atomic status -p
============================================================
* DEFAULT ON BOOT
—————————————-
version    7.0.0
timestamp  2014-11-01 20:22:01
id         dcf0c846ff87f251d48439f6c90948f1183654a9b9d46b28c3f5e0f42c1ddf8e.0
osname     rhel-atomic-host
refspec    rhel-atomic-host-beta-ostree:rhel-atomic-host/7/x86_64/standard
============================================================

-bash-4.2# rpm-ostree status
VERSION   ID             OSNAME               REFSPEC
* 7.0.0     dcf0c846ff     rhel-atomic-host     rhel-atomic-host-beta-ostree:rhel-atomic-host/7/x86_64/standard

Step 3 : Registered the system using subscription manager.

-bash-4.2# subscription-manager list

+——————————————-+
Installed Product Status
+——————————————-+
Product Name:   Red Hat Enterprise Linux Server
Product ID:     69
Version:        7.0
Arch:           x86_64
Status:         Subscribed
Status Details:
Starts:         03/05/2015
Ends:           04/03/2015

Product Name:   Red Hat Enterprise Linux Atomic Host Beta
Product ID:     272
Version:        7-Beta
Arch:           x86_64
Status:         Subscribed
Status Details:
Starts:         03/05/2015
Ends:           04/03/2015

Step 4 : Issue the below command to start the upgrade process.

-bash-4.2# atomic upgrade
Updating from: rhel-atomic-host-beta-ostree:rhel-atomic-host/7/x86_64/standard

613 metadata, 3173 content objects fetched; 122756 KiB transferred in 652 seconds
Copying /etc changes: 10 modified, 4 removed, 35 added
Transaction complete; bootconfig swap: yes deployment count change: 1
Changed:

Step 5 : After completion of upgrade rebooted the server and checked the status using below command.

-bash-4.2# atomic status -p
============================================================
* DEFAULT ON BOOT
—————————————-
version    7.0.1
timestamp  2014-12-11 19:27:46
id         18a9998c80adb6986bf3c7c9eb31c1f9d408d074fdac0ee37a6074ea2be218b4.0
osname     rhel-atomic-host
refspec    rhel-atomic-host-beta-ostree:rhel-atomic-host/7/x86_64/standard
============================================================
NON-DEFAULT ROLLBACK TARGET
—————————————-
version    7.0.0
timestamp  2014-11-01 20:22:01
id         dcf0c846ff87f251d48439f6c90948f1183654a9b9d46b28c3f5e0f42c1ddf8e.0
osname     rhel-atomic-host
refspec    rhel-atomic-host-beta-ostree:rhel-atomic-host/7/x86_64/standard
============================================================

Step 6 : I can see the newer version of docker as well.

-bash-4.2# docker version
Client version: 1.3.2
Client API version: 1.15
Go version (client): go1.3.1
Git commit (client): 39fa2fa/1.3.2
OS/Arch (client): linux/amd64
Server version: 1.3.2
Server API version: 1.15
Go version (server): go1.3.1
Git commit (server): 39fa2fa/1.3.2