Friday, June 29, 2018

Adding Packages to RHEL Containers on Amazon EC2 with Cloud Access

I just ran into an interesting use case, where I'd needed to be able to add packages to my RHEL containers, when they are hosted on Amazon's EC2.  Anyone else who has tried this may have run into the same problem, that RHEL subscription information isn't passed to containers, by default, when run on cloud access instances.

For example:

# podman run --rm -it registry.access.redhat.com/rhel7
[root@7a52d3bac972 /]# yum install httpd
Loaded plugins: ovl, product-id, search-disabled-repos, subscription-manager
This system is not receiving updates. You can use subscription-manager on the host to register and assign subscriptions.
There are no enabled repos.
 Run "yum repolist all" to see the repos you have.
 To enable Red Hat Subscription Management repositories:
     subscription-manager repos --enable <repo>
 To enable custom repositories:
     yum-config-manager --enable <repo>

In order to work around this, you can use bind mounts, as described in the podman man page, in the section on --volume.  There are a number of files and directories that you will need to mount.  In the below example, you can see a successful run:

# podman run \-v /etc/pki/rhui:/etc/pki/rhui \-v /etc/yum/pluginconf.d:/etc/yum/pluginconf.d \ -v /etc/yum/pluginconf.d/rhnplugin.conf:/etc/yum/pluginconf.d/rhnplugin.conf \-v /etc/yum.repos.d/redhat-rhui.repo:/etc/yum.repos.d/redhat-rhui.repo \-v /etc/yum.repos.d/redhat-rhui-client-config.repo:/etc/yum.repos.d/redhat-rhui-client-config.repo \-v /etc/yum.repos.d/rhui-load-balancers.conf:/etc/yum.repos.d/rhui-load-balancers.conf \-v /usr/lib/yum-plugins:/usr/lib/yum-plugins \-v /usr/share/rhn:/usr/share/rhn \-v /usr/share/yum-plugins:/usr/share/yum-plugins \--rm -it registry.access.redhat.com/rhel7

For an offline run of the container, you will need to copy in those same files.  However, if you only want to install files to a container running on persistent storage, temporary mapping of the RHUI-required files and directories is sufficient.

No comments:

Post a Comment