コンテナーおよびクラウドベースの開発のスタートガイド

Red Hat CodeReady Studio 12.19

Red Hat CodeReady Studio を使用したコンテナーおよびクラウドベースのアプリケーション開発

Eva-Lotte Gebhardt

Levi Valeeva

Supriya Takkhi

Red Hat Developer Group Documentation Team

概要

本書のトピックでは、コンテナー化されたアプリケーションの開発や、クラウドデプロイメントのアプリケーションの開発を始める方法を説明します。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。まずは、マスター (master)、スレーブ (slave)、ブラックリスト (blacklist)、ホワイトリスト (whitelist) の 4 つの用語の置き換えから始めます。この取り組みは膨大な作業を要するため、今後の複数のリリースで段階的に用語の置き換えを実施して参ります。詳細は、弊社 の CTO、Chris Wright のメッセージ を参照してください。

第1章 CodeReady Studio でコンテナーおよびクラウドを使用した開発

1.1. CodeReady Studio での Red Hat CodeReady Containers ツールの使用

Red Hat CodeReady Containers (CRC) は、ローカルシステムに最小限の OpenShift 4 クラスターを提供します。このクラスターは、開発およびテストを目的とする最低限の環境を提供します。これは主に開発者のデスクトップでの実行を目的としています。ヘッドレス、複数開発者、またはチームベースのセットアップなどの他のユースケースでは、完全な OpenShift インストーラー を使用することが推奨されます。

OpenShift の詳細は、OpenShift のドキュメント を参照してください。

1.1.1. Red Hat CodeReady コンテナーのダウンロードおよびインストール

CodeReady Studio で CodeReady コンテナーを設定する方法を説明します。

前提条件

  1. 最新リリースの CodeReady Containers とプルシークレットをダウンロード しておく必要があります。
  2. CRC ファイルの展開。

    CRC のインストールおよび設定方法の詳細は、『Getting started with CodeReady Containers Guide』の「Installation」の章を参照してください。

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs opening servers view
  3. 検索フィールドに Server と入力します。
  4. Servers を選択します。
  5. Open をクリックします。

    Servers ビューが表示されます。

    crs servers view empty
  6. Servers ビューの任意の場所をクリックします。

    crs srver view creating new server
  7. NewServer とクリックします。

    Define a New Server ウィンドウが表示されます。

    crs creating crc server
  8. CodeReady Containers 1.0+ を選択します。
  9. Next をクリックします。

    CodeReady Containers ウインドウが表示されます。

    crs crc server adapter creation
  10. Browse をクリックして CRC binary を見つけます。
  11. Browse をクリックして CRC Pull Secret File を見つけます。
  12. Finish をクリックします。

新たに追加された CodeReady Containers 1.0+ サーバーアダプターが Servers ビューに表示されます。

crs crc server adapter created
注記

サーバーアダプターを起動する前に CRC を設定しなかった場合は、CRC has not been properly initialized! という警告が表示されます。

crs crc warning

画面の指示に従って CRC を初期化します。

手順では、開発を支援するために、任意の匿名による使用状況データ収集を求めるプロンプトが表示されます。個人を特定できる情報は収集されません。後で設定を変更する方法については、「Red Hat CodeReady Containers - Consent for telemetry data collection」を参照してください。

1.1.2. OpenShift Container Platform ツールの使用

CodeReady Studio で OpenShift コンテナーを使用する方法を説明します。

前提条件

手順

  1. CodeReady Studio を起動します。
  2. CRC サーバーアダプターを起動します。

    crs starting crc server adapter
  3. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs os explorer view
  4. 検索フィールドに OpenShift と入力します。
  5. OpenShift Explorer を選択します。
  6. Open をクリックします。

    OpenShift Explorer ビューが表示されます。

    crs os explorer view2

    新しい OpenShift コネクションの設定方法については、「Creating a new OpenShift Container Platform connection」を参照してください。

  7. Ctrl+N キーを押します。

    Select a wizard ウインドウが表示されます。

    crs openshift app creation
  8. 検索フィールドに OpenShift と入力します。
  9. OpenShift Application を選択します。
  10. Next をクリックします。

    Sign in to OpenShift ウィンドウが表示されます。

    crs crc sing in to os
  11. クレデンシャルを入力し、Next をクリックします。

    Create OpenShift Project ウインドウが表示されます。

    crs new os project window
  12. プロジェクトに名前を付けます。
  13. Finish をクリックします。

    Select template ウインドウが表示されます。

    crs crc os select a template
  14. テンプレートを選択します。
  15. Next をクリックします。

    Template Parameters ウインドウが表示されます。

    crs template parameters
  16. テンプレートパラメーターが正しいことを確認します。
  17. Finish をクリックします。

    Create Application Summary ウィンドウが表示されます。

    crs create application summary
  18. アプリケーションの詳細が正しいことを確認します。
  19. OK をクリックします。

    Import OpenShift Application ウインドウが表示されます。

    crs import os application
  20. git リポジトリーをクローンする場所を選択します。
  21. Finish をクリックします。

新たに作成された OpenShift プロジェクトとアプリケーションが OpenShift Explorer ビューに表示されます。

crs os project created

その他のリソース

1.2. CodeReady Studio での Red Hat Container Development Kit ツールの使用

Red Hat Container Development Kit (CDK) は、Red Hat Enterprise Linux (RHEL) をベースとした事前にビルドされたコンテナー開発環境です。CDK は、コンテナーベースのアプリケーションをすぐに開発できるようにします。

1.2.1. Container Development Kit のインストール

CodeReady Studio 内から CDK をインストールする方法を説明します。

前提条件

  • ハイパーバイザーがシステムにインストールされ、設定されていることを確認します。

    • VirtualBox、Linux KVM/libvirt (Linux)
    • xhyve (macOS)
    • Hyper-V (Windows)
  • システムでハードウェアの仮想化が有効になっていることを確認します。

    詳細は『Setting Up the Virtualization Environment』を参照してください。

  • Red Hat Developer アカウントがあることを確認してください。

    新規アカウントを作成するには、developers.redhat.com にアクセスします。

CDK の詳細は『Red Hat Container Development Kit Getting Started Guide』を参照してください。

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs opening servers view
  3. 検索フィールドに Server と入力します。
  4. Servers を選択します。
  5. Open をクリックします。

    Servers ビューが表示されます。

    crs servers view empty
  6. Servers ビューの任意の場所をクリックします。

    crs srver view creating new server
  7. NewServer とクリックします。

    Define a New Server ウィンドウが表示されます。

    crs creating cdk server
  8. Red Hat Container Development Kit 3.2+ を選択します。
  9. Next をクリックします。

    Red Hat Container Development Environment ウインドウが表示されます。

    crs creating cdk server2
  10. Download and install runtime をクリックします。

    Download Runtimes ウィンドウが表示されます。

    crs cdk runtimes
  11. Red Hat CDK バージョンを選択します。
  12. Next をクリックします。
  13. access.redhat.com のログインクレデンシャルが正しいことを確認します。
  14. Next をクリックします。
  15. ライセンス契約書を読み、承諾してから Next をクリックします。
  16. インストールフォルダーを選択し、Finish をクリックします。

    ランタイムのダウンロードおよびインストールが完了するまで時間がかかることがあるため注意してください。

  17. Finish をクリックします。

    新たに作成された Container Development Environment 3.2+ サーバーが Servers ビューに表示されます。

    crs cdk server in view
  18. CDK server adapterStart を右クリックします。

    crs startink cdk server adapter
    注記

    サーバーアダプターを起動する前に CDK を設定しなかった場合は、CDK has not been properly initialized! という警告が表示されます。

    crs cdk warning

    画面の指示に従って CDK を初期化します。

1.2.2. Docker ツールの使用

1.2.2.1. Dockerfile の作成

前提条件

  • CDK サーバーアダプターが設定済みである。

    詳細は、「CDK のインストール」を参照してください。

手順

  1. CodeReady Studio を起動します。
  2. CDK サーバーアダプターを起動します。

    crs startink cdk server adapter
  3. Ctrl+N キーを押します。

    Select a wizard ウインドウが表示されます。

    crs java project wizard
  4. 検索フィールドに Java Project と入力します。
  5. Java Project を選択します。
  6. Next をクリックします。

    New Java Project ウインドウが表示されます。

    crs java project creation
  7. プロジェクトに名前を付けます。

    New module-info.java ウィンドウが表示されます。

    crs create module info java
  8. 新しい module-info.java ファイルを作成するか、Don't Create をクリックします。
  9. Finish をクリックします。

    crs java project new file

    新たに作成された Java プロジェクトが Project Explorer ビューに表示されます。

  10. Java projectNewFile を右クリックします。

    Create New File ウインドウが表示されます。

    crs creating docker file
  11. 親フォルダーを選択します。
  12. ファイルに名前を付けます。
  13. Finish をクリックします。

    新たに作成されたファイルが CodeReady Studio エディターに表示されます。

  14. 新たに作成されたファイルに以下の内容を貼り付けます。

        # Use latest jboss/base-jdk:8 image as the base
    FROM jboss/base-jdk:8
    
    # Set the WILDFLY_VERSION env variable
    ENV WILDFLY_VERSION 10.1.0.Final
    ENV WILDFLY_SHA1 9ee3c0255e2e6007d502223916cefad2a1a5e333
    ENV JBOSS_HOME /opt/jboss/wildfly
    
    USER root
    
    # Add the WildFly distribution to /opt, and make wildfly the owner of the extracted tar content
    # Make sure the distribution is available from a well-known place
    RUN cd $HOME \
        && curl -O https://download.jboss.org/wildfly/$WILDFLY_VERSION/wildfly-$WILDFLY_VERSION.tar.gz \
        && sha1sum wildfly-$WILDFLY_VERSION.tar.gz | grep $WILDFLY_SHA1 \
        && tar xf wildfly-$WILDFLY_VERSION.tar.gz \
        && mv $HOME/wildfly-$WILDFLY_VERSION $JBOSS_HOME \
        && rm wildfly-$WILDFLY_VERSION.tar.gz \
        && chown -R jboss:0 ${JBOSS_HOME} \
        && chmod -R g+rw ${JBOSS_HOME}
    
        # Ensure signals are forwarded to the JVM process correctly for graceful shutdown
        ENV LAUNCH_JBOSS_IN_BACKGROUND true
    
        USER jboss
    
        # Expose the ports we're interested in
        EXPOSE 8080
    
        # Set the default command to run on boot
        # This will boot WildFly in the standalone mode and bind to all interface
        CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0"]
  15. Ctrl+S キーを押して変更を保存します。

Dockerfile が作成されます。

その他のリソース

1.2.2.2. Red Hat Container Development Kit を使用した Docker イメージのビルド

前提条件

  • CDK サーバーアダプターが設定済みである。

    詳細は、「CDK のインストール」を参照してください。

  • Java プロジェクトおよび Dockerfile。

    詳細は、「Dockerfile の作成」を参照してください。

手順

  1. CodeReady Studio を起動します。
  2. CDK サーバーアダプターを起動します。

    crs startink cdk server adapter
  3. Java プロジェクトを展開します。

    crs run as docker image build
  4. DockerfileRun asDocker Image Build を右クリックします。

    Docker Image Build Configuration ウインドウが表示されます。

    crs creating docker image
  5. コネクションとして Container Development Environment サーバーアダプターを選択します。
  6. イメージに名前を付けます。
  7. OK をクリックします。

Console ビューが表示され、docker イメージのビルドプロセスが表示されます。

1.2.3. その他のリソース

第2章 CodeReady Studio で OpenShift を使用したクラウド向けの開発

2.1. CodeReady Studio での OpenShift Container Platform アプリケーションの作成

OpenShift Container Platform ツールを使用すると、OpenShift Container Platform アプリケーションを作成、インポート、および変更できます。

2.1.1. 新規 OpenShift Container Platform コネクションの作成

CodeReady Studio で OpenShift ツールを使用するには、OpenShift Explorer ビューで OpenShift コネクションを作成する必要があります。OpenShift コネクションは、CodeReady Studio を OpenShift インスタンス (CDK、OpenShift Online、Kubernetes、minishift をベースとした) に接続します。コネクションは OpenShift Explorer ビューに表示されます。CodeReady Studio に複数の OpenShift コネクションを設定できます。

前提条件

  1. CodeReady Containers サーバーアダプターが実行中である。

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs os explorer view
  3. 検索フィールドに OpenShift と入力します。
  4. OpenShift Explorer を選択します。
  5. Open をクリックします。

    OpenShift Explorer ビューが表示されます。

    crs os explorer new connection
  6. OpenShift Explorer の任意の場所を右クリックします。
  7. NewConnection とクリックします。

    Sign in to OpenShift ウィンドウが表示されます。

    crs os new connection sign in
  8. Server フィールドに OpenShift サーバーの URL を貼り付けます。
  9. トークンまたはログインクレデンシャルを使用して認証します。

    注記

    または、ログインコマンドを OpenShift Container Platform Web UI からコピーすることもできます。

    ログインクレデンシャルを取得するには、drop-down menu in the top right cornerCopy Login Command とクリックします。

    os3 clicking copy login command
  10. Finish をクリックします。

新たに追加されたコネクションが OpenShift Explorer ビューに表示されます。

2.1.2. 新規 OpenShift Container Platform プロジェクトの作成

OpenShift Container Platform の通常ユーザーのリソースへのアクセスを一元管理するには、追加のアノテーションを持つ namespace である OpenShift Container Platform プロジェクトを作成する必要があります。

前提条件

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs os explorer view
  3. 検索フィールドに OpenShift と入力します。
  4. OpenShift Explorer を選択します。
  5. Open をクリックします。

    OpenShift Explorer ビューが表示されます。

    crs os new project
  6. OpenShift Container Platform connectionNewProject を右クリックします。

    New OpenShift Project ウインドウが表示されます。

    crs new os project window
  7. プロジェクトに名前を付けます。
  8. Finish をクリックします。

新たに作成された OpenShift プロジェクトが OpenShift Explorer ビューに表示されます。

crs os project created

2.1.3. 新規 OpenShift Container Platform アプリケーションの作成

CodeReady Studio の OpenShift Application ウィザードを使用して、デフォルトまたはカスタムテンプレートから OpenShift Container Platform アプリケーションを作成できます。

前提条件

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs os explorer view
  3. 検索フィールドに OpenShift と入力します。
  4. OpenShift Explorer を選択します。
  5. Open をクリックします。

    OpenShift Explorer ビューが表示されます。

    crs os new app
  6. OpenShift Container Platform connectionNewApplication を右クリックします。

    Select template ウインドウが表示されます。

    crs crc os selecting template
  7. テンプレートを選択します。
  8. Next をクリックします。

    Template Parameters ウインドウが表示されます。

    crs template parameters
  9. テンプレートパラメーターが正しいことを確認します。
  10. Next をクリックします。

    Resource Labels ウィンドウが表示されます。

    crs os resource label
  11. Add をクリックしてラベルを追加します。
  12. Finish をクリックします。

    Create Application Summary ウィンドウが表示されます。

    crs os app summary
  13. アプリケーションの詳細が正しいことを確認します。
  14. OK をクリックします。

    Import OpenShift Application ウインドウが表示されます。

    crs git clone location
  15. git リポジトリーをクローンする場所を選択します。
  16. Finish をクリックします。

新たに作成された OpenShift Container Platform アプリケーションが OpenShift Explorer ビューに表示されます。

その他のリソース

  • OpenShift Container Platform でテンプレートを使用および作成する方法については、アップストリームのドキュメント「Official OKD documentation, Using templates」を参照してください。

2.1.4. 既存の OpenShift Container Platform アプリケーションの CodeReady Studio へのインポート

CodeReady Studio の OpenShift Explorer ビューには、OpenShift Container Platform アカウントに関連付けられたアプリケーションが表示されます。Import OpenShift Application ウィザードを使用すると、これらのアプリケーションのソースコードを個別に CodeReady Studio にインポートできます。アプリケーションをインポートした後、アプリケーションのソースコードの変更、アプリケーションのビルド、およびWeb ブラウザーでの表示を簡単に行うことができます。

前提条件

  • CodeReady Studio にインポートするアプリケーションのソースは build config ファイルに指定されている必要があります。
  • OpenShift Container Platform コネクション。

    OpenShift Container Platform コネクションを作成する方法の詳細は、「新規 OpenShift Container Platform コネクションの作成」を参照してください。

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs os explorer view
  3. 検索フィールドに OpenShift と入力します。
  4. OpenShift Explorer を選択します。
  5. Open をクリックします。

    OpenShift Explorer ビューが表示されます。

    crs import os app
  6. OpenShift Container Platform connectionImport OpenShift Application を右クリックします。

    Select Build Config ウインドウが表示されます。

    crs select build config
  7. インポートするアプリケーションを選択します。
  8. Next をクリックします。

    Import OpenShift Application ウインドウが表示されます。

    crs git clone location
  9. Git Clone Location を選択します。
  10. Finish をクリックします。

新たにインポートされた OpenShift Container Platform アプリケーションが OpenShift Explorer ビューに表示されます。

2.1.5. サーバーアダプターを使用したアプリケーションのデプロイ

サーバーアダプターを使用すると、ワークスペースプロジェクトに追加した変更を OpenShift インスタンス上で実行中の OpenShift アプリケーションにパブリッシュできます。これにより、アプリケーションの変更部分を OpenShift にデプロイされた Pod に直接デプロイできます。サーバーアダプターを使用すると、ソースコードを Git リポジトリーにコミットせずに、アプリケーションの変更を直接実行中の OpenShift アプリケーションにプッシュできます。

前提条件

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs os explorer view
  3. 検索フィールドに OpenShift と入力します。
  4. OpenShift Explorer を選択します。
  5. Open をクリックします。

    OpenShift Explorer ビューが表示されます。

    crs os app server adapter
  6. OpenShift Container Platform コネクションを展開します。
  7. applicationServer Adapterを右クリックします。

    Server Settings ウィンドウが表示されます。

    crs os server settings
    注記

    EAP 7.3 を使用している場合は、テンプレートの変更によりサーバーアダプターのデプロイメントのパスを設定する必要があります。

    これを行うには、Use inferred Pod Deployment Path チェックボックスのチェックマークを削除し、Pod Deployment Path フィールドを /opt/eap/standalone/deployments/ に設定します。

  8. Finish をクリックします。

Servers ビューが表示され、サーバーアダプターを起動します。

ブラウザーでアプリケーションを開くには、 applicationShow InWeb Browser を右クリックします。

crs os app show in browser

CodeReady Studio の組み込み Web ブラウザーが開かれ、アプリケーションが表示されます。

2.1.6. OpenShift Container Platform プロジェクトの削除

プロジェクトの開発を新たに開始する場合や、プロジェクトの開発が終了した後に、ワークスペースからプロジェクトを削除することがあります。プロジェクトを削除すると、プロジェクトに関連付けられたリソースもすべて削除されます。

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs os explorer view
  3. 検索フィールドに OpenShift と入力します。
  4. OpenShift Explorer を選択します。
  5. Open をクリックします。

    OpenShift Explorer ビューが表示されます。

    crs os project delete
  6. OpenShift Container Platform コネクションを展開します。
  7. projectDelete を右クリックします。

    Delete OpenShift Resource ウィンドウに同意を求めるプロンプトが表示されます。

  8. OK をクリックします。

これでプロジェクトが削除されます。

2.2. CodeReady Studio での OpenShift Container Platform アプリケーションの設定およびリモート監視

CodeReady Studio を使用すると、ユーザーは OpenShift Container Platform のリモートインスタンスへのコネクションを設定し、アプリケーションを使用して、ログをビルドし、実行中のアプリケーションをトラブルシューティングおよび監視できます。

2.2.1. OpenShift Client Binaries の設定

前提条件

ポート転送の設定や、アプリケーションおよびビルドログのストリーミングを行う前に、OpenShift Client Binaries を設定します。

手順

  1. CodeReady Studio を起動します。
  2. WindowPreferences をクリックします。

    Preferences ウィンドウが表示されます。

    crs jboss os
  3. 検索フィールドに OpenShift と入力します。
  4. OpenShift を選択します。
  5. Browse をクリックして、oc 実行可能ファイルを見つけます。
  6. Apply and Close をクリックします。

これで、OpenShift Client Binaries が設定されます。

2.2.2. ポート転送の設定

Application Port Forwarding ウィンドウを使用すると、ローカルポートをリモートポートに接続し、データのアクセスやアプリケーションのデバッグを行うことができます。

以下のいずれかの理由で、ポート転送は自動的に停止します。

  • OpenShift Container Platform コネクションの終了
  • CodeReady Studio のシャットダウン
  • ワークスペースの変更

ポート転送は、CodeReady Studio から OpenShift Container Platform に接続するたびに有効にする必要があります。

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs os explorer view
  3. 検索フィールドに OpenShift と入力します。
  4. OpenShift Explorer を選択します。
  5. Open をクリックします。

    OpenShift Explorer ビューが表示されます。

    crs port forwarding
  6. OpenShift Container Platform コネクションを展開します。
  7. applicationPort Forwarding を右クリックします。

    Port Forwarding ウィンドウが表示されます。

    crs start port forwarding
  8. Find free local ports for remote ports ボックスを選択します。
  9. Start All をクリックします。
  10. OK をクリックします。

Console ビューが表示され、ポート転送の開始プロセスが表示されます。

2.2.3. Pod ログのストリーミング

Pod ログは、リモート OpenShift Container Platform インスタンスで実行されるアプリケーションの一般的なログです。CodeReady Studio のストリーミング Pod ログ機能は、アプリケーションを監視し、アプリケーションが失敗したりエラーを返した場合に以前の Pod ログを使用してトラブルシューティングを行います。

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs os explorer view
  3. 検索フィールドに OpenShift と入力します。
  4. OpenShift Explorer を選択します。
  5. Open をクリックします。

    OpenShift Explorer ビューが表示されます。

    crs pod log
  6. OpenShift Container Platform コネクションを展開します。
  7. applicationPod Log を右クリックします。

Console ビューが表示され、Pod ログが表示されます。

2.2.4. ビルドログのストリーミング

ビルドログは、リモート OpenShift Container Platform インスタンスで実行されているアプリケーションへの変更を記録するログです。CodeReady Studio のストリーミングビルドログ機能は、アプリケーションのビルドプロセスの進捗や、アプリケーションのデバッグに使用されます。

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs os explorer view
  3. 検索フィールドに OpenShift と入力します。
  4. OpenShift Explorer を選択します。
  5. Open をクリックします。

    OpenShift Explorer ビューが表示されます。

    crs streaming build logs
  6. OpenShift Container Platform コネクションを展開します。
  7. applicationBuild Log を右クリックします。

Console ビューが表示され、ビルドログが表示されます。

2.3. その他のリソース

第3章 CodeReady Studio での Docker による開発

3.1. Docker コネクションの管理

3.1.1. Docker アカウントの設定

CodeReady Studio で Docker アカウントを設定する方法を説明します。

前提条件

  • Docker がシステムにインストールされている。

    Docker のインストール方法は、Docker Docs の「Get Docker」を参照してください。

  • Docker ID を持っている。

    Docker ID を取得する方法の詳細は「Register for a Docker ID」を参照してください。

手順

  1. CodeReady Studio を起動します。
  2. WindowPreferences をクリックします。

    Preferences ウィンドウが表示されます。

    crs registry accounts
  3. 検索フィールドに Registry Accounts と入力します。
  4. Registry Accounts を選択します。
  5. Add をクリックします。

    New Registry Account ウィンドウが表示されます。

    crs docker new account registry
  6. Server Address を入力します。
  7. Docker ID を Username として入力します。
  8. Docker アカウントに関連するメールを入力します。
  9. パスワードを入力します。
  10. OK をクリックします。
  11. Apply and Close をクリックします。

Docker アカウントが設定されます。

3.1.2. 既存の Docker コネクションのテスト

前提条件

  • CodeReady Studio で Docker アカウントが設定されている。

    CodeReady Studio に Docker アカウントを設定する方法の詳細は、「Docker アカウントの設定」を参照してください。

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs opening docker explorer
  3. 検索フィールドに Docker と入力します。
  4. Docker Explorer を選択します。
  5. Open をクリックします。

    Docker Explorer ビューが表示されます。

    crs docker explorer
  6. Docker socketEdit を右クリックします。

    crs docker socket edit

    Edit Docker Connection ウインドウが表示されます。

    crs docker testing connection
  7. Test Connection をクリックします。

    コネクションが正しく設定されていれば、Ping succeeded! を示すウィンドウが表示されます。

  8. OK をクリックします。
  9. Finish をクリックします。

3.1.3. Docker コネクションの編集

前提条件

  • CodeReady Studio に Docker アカウントが設定されている。

    CodeReady Studio に Docker アカウントを設定する方法の詳細は、「Docker アカウントの設定」を参照してください。

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs opening docker explorer
  3. 検索フィールドに Docker と入力します。
  4. Docker Explorer を選択します。
  5. Open をクリックします。

    Docker Explorer ビューが表示されます。

    crs docker explorer
  6. Docker socketEdit を右クリックします。

    crs docker socket edit

    Edit Docker Connection ウインドウが表示されます。

    crs docker testing connection
  7. Unix socket Location フィールドで Browse をクリックして新しいソケットを見つけるか、TCP Connection オプションを選択してホスト URI を追加します。
  8. Finish をクリックします。

Docker コネクションが編集されます。

3.2. Docker イメージの管理

3.2.1. Docker イメージのプル

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs opening docker explorer
  3. 検索フィールドに Docker と入力します。
  4. Docker Explorer を選択します。
  5. Open をクリックします。

    Docker Explorer ビューが表示されます。

    crs docker explorer
  6. Docker socket フォルダーを展開します。
  7. ImagesPull を右クリックします。

    crs docker pull images

    Pull Image ウインドウが表示されます。

    crs docker pull image window
  8. Search をクリックします。

    Search the Docker Registry for images ウィンドウが表示されます。

    crs docker pulling wildfly image
  9. 検索フィールドにイメージ名を入力します。
  10. Next をクリックします。

    Choose a tag for the selected image ウィンドウが表示されます。

    crs docker images tags
  11. イメージのタグを選択します。
  12. Finish をクリックします。

    Pull an image or a repository from the registry ウインドウが表示されます。

    crs docker pulling wildfly image2
  13. Finish をクリックします。

新しい Docker イメージが Docker Explorer ビューに表示されます。

crs docker pulled image

3.2.2. Docker イメージのプッシュ

イメージをプッシュする前に、タグを付ける必要があります。CodeReady Studio で Docker イメージにタグを付け、プッシュする方法を説明します。

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs opening docker explorer
  3. 検索フィールドに Docker と入力します。
  4. Docker Explorer を選択します。
  5. Open をクリックします。

    Docker Explorer ビューが表示されます。

    crs docker explorer
  6. Docker socketImages を展開します。
  7. タグを付けるイメージを右クリックします。
  8. Add tag をクリックします。

    crs docker tag image

    Tag Image ウインドウが表示されます。

    crs docker tagging image
  9. タグを New Tag フィールドに入力します。

    タグは username/image_name:tag_name の形式で指定する必要があります。ここで、usernamehub.docker.com 上の Docker ID、image_name はイメージの名前、tag_name はイメージのバージョンに置き換えます。

  10. Finish をクリックします。
  11. tagged imagePush を右クリックします。

    crs docker pushing tagged image

    Push image to Registry ウインドウが表示されます。

    crs docker image push
  12. Docker ID で始まる Registry Account を選択します。
  13. Finish をクリックします。

イメージをプッシュすると、Docker Cloud に表示されます。その後、このイメージは他の開発者が使用できるようになります。

3.2.3. Docker イメージの実行

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs opening docker explorer
  3. 検索フィールドに Docker と入力します。
  4. Docker Explorer を選択します。
  5. Open をクリックします。

    Docker Explorer ビューが表示されます。

    crs docker explorer
  6. Docker socketImages を展開します。
  7. 実行するイメージを右クリックします。
  8. Run クリックします。

    crs docker running image

    Docker Container settings ウィンドウが表示されます。

    crs docker container settings
  9. コンテナーに名前を付けます。
  10. Publish all exposed ports to random ports on the host interfaces チェックボックスを非選択にします。
  11. 8080 ポートのボックスを選択します。
  12. Finish をクリックします。

    Console ビューが表示され、イメージを起動するプロセスが表示されます。

  13. Web ブラウザーで http://localhost:8080/ に移動し、実行中のイメージを確認します。

    crs docker image running

3.2.4. Dockerfile でのイメージのビルド

既存のイメージを変更して、イメージをビルドまたは作成できます。通常、これには新しいパッケージをインストールする必要があります。新しい Docker イメージの指定は、Dockerfile で行います。

前提条件

  • ローカルマシンに Dockerfile が作成されている。

    Dockerfile の作成方法についての詳細は、「Dockerfile の作成」を参照してください。

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs opening docker images view
  3. 検索フィールドに Docker と入力します。
  4. Docker Images を選択します。
  5. Open をクリックします。

    Docker Images ビューが表示されます。

    crs docker images view
  6. イメージの Build Image アイコンをクリックします。

    crs docker build image icon

    Build a Docker Image ウィンドウが表示されます。

    crs building a docker image
  7. repo/name:version の形式で、イメージに名前を付けます。
  8. Browse をクリックして Dockerfile を見つけます。
  9. Finish をクリックします。

Console ビューが表示され、ビルドのプロセスが表示されます。

3.3. Docker コンテナーの管理

Docker コンテナーは、Docker イメージを基にした分離されたプロセスです。コンテナーの作成後、ユーザーはコンテナーを停止、起動、一時停止、一時停止解除、kill、または削除できます。また、コンテナーのログの読み取りも可能です。

CodeReady Studio で Docker コンテナーを管理する方法を説明します。

手順

  1. CodeReady Studio を起動します。
  2. WindowShow ViewOther とクリックします。

    Show View ウインドウが表示されます。

    crs opening docker containers view
  3. 検索フィールドに Docker と入力します。
  4. Docker Containers を選択します。
  5. Open をクリックします。

    Docker Containers ビューが表示されます。

    crs docker containers view

パネルを使用して、コンテナーを起動、一時停止、一時停止解除、停止、kill、再開、削除、または更新できます。

crs docker containers control panel

法律上の通知

Copyright © 2021 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.