Running Containerized (Docker) Applications on a RHEL Instance of an Amazon AMI

With RHEL specific containers running on a registered instance of RHEL, the Redhat docker container that you obtain from Red Hat will inherit the entitlements of the machine/host/host VM that you run the container on - make sense? If you run the appropriate subscription manager commands, and set your entitlements, you should be able to use your RHEL base image and build your application from that. However, if you need to build/run your docker container/image on an Amazon AMI specific to Redhat, you run into some speed-bumps - I won’t refer to them as roadblocks, because there is a way to do this.

Start with an Amazon AMI - I used a free tier one for demo purposes:

Of course, make certain that it is a 64-bit VM.

Make sure you add some storage, you may need it if you are going to do some real work. However, for testing purposes, I selected the default:

Give it a name - so you don’t get too confused!

Also - be sure to give it a security group - you will need to allow ssh access

Select a key pair during launch: Connect to the new instance with the key pair that you selected:

Connect to the new instance with the key pair that you selected:

Once you have launched your instance, you are going to need to register it with your Red Hat account - for entitlement purposes. The Amazon instance uses RHUI, which does not, in our case, give you access to what you require.

Once you login to your instance, it’s best to work as sudo in this case:

$sudo bash

At this time, you will see a root prompt:

[root@ip-172-31-44-8 ]#

At this time, you are going to need to register using subscription manager.

sudo subscription-manager register --username=rhnuser --password=rhnpasswd --auto-attach

sudo subscription-manager repos --disable="*"

sudo subscription-manager repos --enable=rhel-7-server-rpms

sudo subscription-manager repos --enable=rhel-7-server-extras-rpms

sudo subscription-manager repos --enable=rhel-7-server-optional-rpms

  1. You would need to register your instance to get entitlements. For this, you would need to register as an ISV so that you can get a Red Hat login and password.
  2. Then list the available pools to you - use the pool ID that suits your needs.
  3. Once you do this, you would need to enable the necessary repos - the above two give you what you need - specifically docker.

Once you have registered your Amazon AMI instance, you would need to install docker.

yum -y install docker

Once docker is installed, start it and enable it to start on boot. Finally, verify that Docker is running:

systemctl start docker.service

systemctl enable docker.service

systemctl status docker.service

docker.service - Docker Application Container Engine

Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled)

Active: active (running) since Thu 2015-05-14 09:59:12 EDT; 1min 46s ago

Docs:

Main PID: 733 (docker)

CGroup: /system.slice/docker.service

└─733 /usr/bin/docker -d --selinux-enabled --add-registry registry.access.redhat.com

(truncated)

Now, grab the RHEL docker image from Red Hat:

docker pull registry.access.redhat.com/rhel

This will grab the latest RHEL base image from Red Hat. After it is complete, verify for yourself:

docker images

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE

registry.access.redhat.com/rhel 7.1-4 10acc31def5d 3 months ago 154.1 MB

registry.access.redhat.com/rhel latest 10acc31def5d 3 months ago 154.1 MB

Now, you can proceed to build a docker container.

I have included a sample one that you can use below:

FROM registry.access.redhat.com/rhel

MAINTAINER "Glen Millard <>"

RUN yum -y update; yum clean all

ENTRYPOINT echo 'we are running some # of cool things here at Red Hat!'

So if you copy/paste the above 4 (four) lines and save it as ‘Dockerfile’ (make sure you name it EXACTLY Dockerfile). Then from the same directory, run the following command:

docker build -t rhel_message .

You will see a bunch of lines scrolling by - most of it involves yum update - not really necessary for this demonstration, but I wanted to illustrate that docker will inherit the software entitlement from the Amazon Red Hat image.

Once it is complete, run the docker container:

docker run rhel_message

we are running some # of cool things here at Red Hat!

If you see the above message, it worked.