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

Red Hat CodeReady Studio 12.16

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

Levi Valeeva

Supriya Takkhi

Red Hat Developer Group Documentation Team

概要

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

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

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

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

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

前提条件

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

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

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

CodeReady Studio で CodeReady コンテナーを設定する方法を説明します。ここでは、本章の前提条件に記載されている手順が完了済みであることを仮定しています。

手順

  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

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 ビューが表示されます。

  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 ウインドウが表示されます。

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

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

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

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

    crs buid config example
  16. ビルド設定が正しいことを確認します。
  17. 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 は、コンテナーベースのアプリケーションをすぐに開発できるようにします。CodeReady Studio 内で CDK を簡単に設定できます。

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

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

前提条件

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

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

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

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

    新規アカウントを作成する場合は、https://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 crc warning

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

1.2.2. Docker ツールの使用

IDE で CDK サーバーを起動したら、2 つあるコンテナー開発ワークフローの 1 つに従って Docker ツールを使用できます。

1.2.2.1. Dockerfile の作成

前提条件

手順

  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. プロジェクトに名前を付けます。
  8. プロジェクトの場所を選択します。
  9. Finish をクリックします。

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

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

    crs java project new file

    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 キーを押して変更を保存します。

その他のリソース

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

前提条件

手順

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

    crs startink cdk server adapter
  3. Java プロジェクトを展開します。
  4. DockerfileRun asDocker Image Build を右クリックします。

    crs run as docker image build

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

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

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

1.2.2.3. その他のリソース

1.2.3. 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 ビューが表示されます。

  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 ウインドウが表示されます。

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

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

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

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

    crs buid config example
  16. ビルド設定が正しいことを確認します。
  17. Finish をクリックします。

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

crs os project created

その他のリソース

1.2.4. その他のリソース

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

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

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

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

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

手順

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

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

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

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

  6. OpenShift Explorer の任意の場所を右クリックします。

    crs os explorer new connection
  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 プロジェクトの作成

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

前提条件

手順

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

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

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

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

  6. OpenShift Container Platform connectionNewProject を右クリックします。

    crs os new project

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

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

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

crs os project created

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

IDE の 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 ビューが表示されます。

  6. OpenShift Container Platform connectionNewApplication を右クリックします。

    crs os new app

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

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

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

  9. Next をクリックします。

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

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

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

    crs os app summary
  12. OK をクリックします。

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

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

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

その他のリソース

  • OpenShift Container Platform でテンプレートを使用および作成する方法については、「Using Templates」を参照してください。

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

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

前提条件

  • IDE にインポートするアプリケーションのソースは 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 ビューが表示されます。

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

    crs import os app

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

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

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

    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 ビューが表示されます。

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

    crs os app server adapter

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

    crs os server settings
  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 ビューが表示されます。

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

    crs os project delete

    Delete OpenShift Resource ウインドウが表示されます。

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

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

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

IDE を使用すると、ユーザーは 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 コネクションの終了
  • IDE のシャットダウン
  • ワークスペースの変更

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

手順

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

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

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

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

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

    crs port 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 インスタンスで実行されるアプリケーションの一般的なログです。IDE のストリーミングアプリケーションログ機能は、アプリケーションを監視し、アプリケーションが失敗したりエラーを返した場合に以前の Pod ログを使用してトラブルシューティングを行います。

手順

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

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

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

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

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

    crs pod log

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

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

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

手順

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

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

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

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

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

    crs build log

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

2.3. その他のリソース

第3章 Docker での開発

前提条件

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

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

  • Docker ID を取得している。

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

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

3.1.1. CodeReady Studio での Docker アカウントの設定

CodeReady Studio で Docker アカウントを設定する方法を説明します。ここでは、本章の前提条件に記載されている手順が完了済みであることを仮定しています。

手順

  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. Docker ハブの Server Address を入力します。
  7. Docker ID を Username として入力します。
  8. Docker アカウントに関連するメールを入力します。
  9. パスワードを入力します。
  10. OK をクリックします。
  11. Apply and Close をクリックします。

3.1.2. 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 コネクションの編集

前提条件

手順

  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 をクリックします。

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 をクリックします。

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

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

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

crs docker pulled image

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

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 ウインドウが表示されます。

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

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

    crs docker tagging image
  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.