第2章 Red Hat Software Collections コンテナーイメージを使用したアプリケーションイメージの構築
Red Hat Software Collections コンテナーイメージを使用してアプリケーションイメージを構築する方法は複数あります。
- Red Hat が提供するコンテナーイメージをベースイメージとして使用する。
- S2I スクリプトを含む Dockerfile を使用する。
-
OpenShift での
Source-to-Image
(S2I) の使用 -
source-to-image
ユーティリティーの使用
2.1. Red Hat Software Collections Images を使用したアプリケーションイメージの構築
Red Hat が提供するコンテナーイメージをベースイメージとして使用するには、以下を実行します。
アプリケーションイメージ用に Dockerfile を作成し、このファイルに次の行が含まれるようにします。
FROM registry.redhat.io/rhscl_image_name
以下の行を Dockerfile に配置して、
src/
ディレクトリーにアプリケーションコードをイメージに追加します。ADD src /opt/app-root/src
podman
を使用してアプリケーションイメージをビルドします。# podman build -t application_image_name .
podman
を使用してアプリケーションイメージを実行します。たとえば、アプリケーションイメージ内でインタラクティブシェルを起動するには、以下を実行します。# podman run -ti application_image_name /bin/bash -l
例2.1 rhscl/python-38-rhel7
ベースイメージを使用して Dockerfile から構築された Django アプリケーション
この例では、rhscl/python-38-rhel7
コンテナーイメージからの単純な Django アプリケーションの作成に使用できる Dockerfile を示しています。
# Set base image FROM registry.redhat.io/rhscl/python-38-rhel7 # Add application sources ADD --chown=1001:0 app-src . # Install the dependencies RUN pip install -U "pip>=19.3.1" && \ pip install -r requirements.txt && \ python manage.py collectstatic --noinput && \ python manage.py migrate # Run the application CMD python manage.py runserver 0.0.0.0:8080