Building a RHEL8-based container image on Docker on macOS

最初のハマりどころ。過去にもハマって思い出せなかったのでメモ。
まず、Registry Service Accountsでアカウントを作成する必要がある。ここでアカウントを作成すると、docker loginなどのコマンドラインが提示されるので、これを利用すればregistry.access.redhat.comのイメージをpullすることが可能になる。

で、これは今日ハマってたところなんだけど、UBI (Universal Base Image)を使ってdhcp-serverパッケージ(RHEL7ではdhcp、RHEL8ではdhcp-serverがサーバとなる)をインストールしようとしたところ出来ない。でも、httpdやnginxはインストール出来る。結論としては、UBIベースでインストール出来るのはBaseOSに含まれる一部のパッケージだけであるということがまず一つ。そしてSubscription ManagerがRHUI (Red Hat Update Infrastructure) を利用していないこと。つまりクラウドのIaaS上のRHEL8ではないこと。Red HatのCertified Cloud ProiderはRHUIの設定が義務づけられているので、それらの環境では下記手順では動かない可能性が高い。

Dockerfileは以下のようになる。smでregisterする必要があるので、ここではDockerfileに書いてるが、まあENVで渡すのがセキュリティ的には良かろう。

FROM registry.access.redhat.com/ubi8/ubi
USER root

RUN subscription-manager register --auto-attach --username=rh-customer-portal-accout --password=rh-customer-portal-password

# Update image
RUN yum update --disableplugin=subscription-manager -y
RUN yum -y --disableplugin=subscription-manager install dhcp-server && rm -rf /var/cache/yum
RUN subscription-manager unregister

# Add default Web page and expose port
EXPOSE 67

# Start the service
ENTRYPOINT ["/usr/sbin/dhcpd"]

I’d like to start from the point I stacked before and couldn’t remember it.
Firstly, you need to create an account at Registry Service Accounts . After creating the account, the command lines such as ‘docker login’ will be shown. You can pull the images from registry.access.redhat.com with them.

Secondly, I stacked another point today. Unfortunately, I couldn’t install the dhcp-server package in RHEL8 which is the replacement of dhcp package in RHEL7 with UBI, Universal Base Image. But I could install httpd and nginx. As a result, I found that I could install the part of packages included in BaseOS by using UBI and the condition to install all the packages in RHEL8 was that Subscription Manager was used, in other words, a system was not connected to RHUI, Red Hat Update Infrastructure. It means that RHEL8 doesn’t run on IaaS. Red Hat’s Certified Cloud Providers are required to use RHUI, so, the following procedure doesn’t work, I guess.

The Dockerfile will be as follows. I put the information used to log in Red Hat Customer Portal by Subscription Manager into the file, but it’s better to pass them as ENV or ARG to docker from the viewpoint of security.

FROM registry.access.redhat.com/ubi8/ubi
USER root

RUN subscription-manager register --auto-attach --username=rh-customer-portal-accout --password=rh-customer-portal-password

# Update image
RUN yum update --disableplugin=subscription-manager -y
RUN yum -y --disableplugin=subscription-manager install dhcp-server && rm -rf /var/cache/yum
RUN subscription-manager unregister

# Add default Web page and expose port
EXPOSE 67

# Start the service
ENTRYPOINT ["/usr/sbin/dhcpd"]
タイトルとURLをコピーしました