

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Docker コンテナとして AWS IoT Greengrass V2 実行されている にコンテナ化されたアプリケーションをデプロイする
<a name="deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container"></a>

*Salih Bakir、Giuseppe Di Bella、Gustav Svalander、Amazon Web Services*

## 概要
<a name="deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container-summary"></a>

AWS IoT Greengrass Version 2は、Docker コンテナとしてデプロイされた場合、Docker アプリケーションコンテナの実行をネイティブにサポートしていません。このパターンは、Docker-in-Docker (DinD) 機能 AWS IoT Greengrass V2 を有効にする の最新バージョンに基づいてカスタムコンテナイメージを作成する方法を示しています。DinD を使用すると、 AWS IoT Greengrass V2 環境内でコンテナ化されたアプリケーションを実行できます。

このパターンは、スタンドアロンソリューションとしてデプロイすることも、Amazon ECS Anywhere などのコンテナオーケストレーションプラットフォームと統合することもできます。どちらのデプロイモデルでも、スケーラブルなコンテナベースのデプロイを有効にしながら、 AWS IoT SiteWise エッジ処理機能を含む完全な AWS IoT Greengrass V2 機能を維持します。

## 前提条件と制限事項
<a name="deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container-prereqs"></a>

**前提条件**
+ アクティブ AWS アカウント。
+ 一般的な AWS IoT Greengrass Version 2 前提条件については、 AWS IoT Greengrass Version 2 ドキュメントの[「前提条件](https://docs.aws.amazon.com/greengrass/v2/developerguide/getting-started-prerequisites.html)」を参照してください。
+ Linux、macOS、または Windows にインストールおよび設定された Docker エンジン。
+ Docker Compose (Docker Compose コマンドラインインターフェイス (CLI) を使用して Docker イメージを実行する場合）。
+ Linux オペレーティングシステム。
+ 仮想化をサポートするホストサーバーを持つハイパーバイザー。
+ システム要件:
  + 2 GB の RAM (最小)
  + 使用可能なディスク容量 5 GB (最小)
  +  AWS IoT SiteWise Edge の場合、16 GB の RAM と 50 GB の使用可能なディスク容量を備えた x86\$164 クアッドコア CPU。 AWS IoT SiteWise データ処理の詳細については、 AWS IoT SiteWise ドキュメントの[「データ処理パックの要件](https://docs.aws.amazon.com/iot-sitewise/latest/userguide/configure-gateway-ggv2.html#w2aac17c19c13b7)」を参照してください。

**製品バージョン**
+ AWS IoT Greengrass Version 2 バージョン 2.5.3 以降
+ Docker-in-Docker バージョン 1.0.0 以降
+ Docker Compose バージョン 1.22 以降
+ Docker エンジンバージョン 20.10.12 以降

**制限事項**
+ 一部の AWS のサービス は では使用できません AWS リージョン。利用可能なリージョンについては、「[AWS サービス (リージョン別)](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)」を参照してください。特定のエンドポイントについては、「[サービスエンドポイントとクォータ](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)」を参照して、サービスのリンクを選択してください。

## アーキテクチャ
<a name="deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container-architecture"></a>

**ターゲットテクノロジースタック**
+ **データソース** – 処理用のデータを生成する IoT デバイス、センサー、または産業機器
+ **AWS IoT Greengrass V2** – エッジインフラストラクチャにデプロイされた D-in-D 機能を備えた Docker コンテナとしての実行
+ **コンテナ化されたアプリケーション** – ネストされた Docker コンテナとして AWS IoT Greengrass V2 環境内で実行されるカスタムアプリケーション
+ **(オプション) Amazon ECS Anywhere** – コンテナのデプロイを管理する AWS IoT Greengrass V2 コンテナオーケストレーション
+ **その他 AWS のサービス** – AWS IoT Core AWS IoT SiteWiseデータ処理と管理 AWS のサービス のための など

**ターゲットアーキテクチャ**

次の図は、コンテナ管理ツールである Amazon ECS Anywhere を使用するターゲットデプロイアーキテクチャの例を示しています。

![\[Amazon ECS Anywhere を使用したデプロイアーキテクチャ。\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/images/pattern-img/2ecf5354-40e0-4fd9-9798-086719059784/images/5ed2652e-9604-4809-8962-b167e1991658.png)


この図表は、次のワークフローを示しています:

**1: コンテナイメージストレージ** – Amazon ECR は、エッジ処理に必要な AWS IoT Greengrass コンテナイメージとカスタムアプリケーションコンテナを保存します。

**2 **および** 3: コンテナのデプロイ** – Amazon ECS Anywhere は AWS IoT Greengrass 、コンテナイメージを Amazon ECR からエッジロケーションにデプロイし、コンテナのライフサイクルとデプロイプロセスを管理します。

**4: コンポーネントのデプロイ** — デプロイされた AWS IoT Greengrass コアは、設定に基づいて関連するコンポーネントを自動的にデプロイします。コンポーネントには、コンテナ化された環境内の AWS IoT SiteWise Edge やその他の必要なエッジ処理コンポーネントが含まれます。

**5: データインジェスト** – 完全に設定されると、 はエッジロケーションのさまざまな IoT データソースからのテレメトリデータとセンサーデータの取り込み AWS IoT Greengrass を開始します。

**6: データ処理とクラウド統合** – コンテナ化された AWS IoT Greengrass コアは、デプロイされたコンポーネント (産業用データの AWS IoT SiteWise Edge を含む) を使用してデータをローカルで処理します。次に、処理されたデータを AWS クラウド サービスに送信して、さらなる分析と保存を行います。

## ツール
<a name="deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container-tools"></a>

**AWS のサービス**
+ [Amazon ECS Anywhere](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/launch-type-external.html) は、Amazon ECS タスクとサービスを独自のインフラストラクチャにデプロイ、使用、管理する際に役立ちます。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) は、 AWS クラウドでスケーラブルなコンピューティング容量を提供します。仮想サーバーを必要な数だけ起動して、迅速にスケールアップまたはスケールダウンができます。
+ [Amazon Elastic Container Registry (Amazon ECR)](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html) は、セキュリティ、スケーラビリティ、信頼性を備えたマネージドコンテナイメージレジストリサービスです。
+ [AWS IoT Greengrass](https://docs.aws.amazon.com/greengrass/v2/developerguide/what-is-iot-greengrass.html) は、デバイス上で IoT アプリケーションを構築、デプロイ、管理するのに役立つオープンソースの IoT エッジランタイムおよびクラウドサービスです。
+ [AWS IoT SiteWise](https://docs.aws.amazon.com/iot-sitewise/latest/userguide/what-is-sitewise.html) は、産業用機器からデータを大規模に収集、モデル化、分析、視覚化するのに役立ちます。

**その他のツール**
+ [Docker](https://www.docker.com/) は、オペレーティングシステムレベルの仮想化を使用してソフトウェアをコンテナで配信するサービスとしての Platform as a Service (PaaS) 製品のセットです。
+ [Docker Compose](https://docs.docker.com/compose/) は、マルチコンテナアプリケーションを定義および実行するためのツールです。
+ [Docker Engine](https://docs.docker.com/engine/) は、アプリケーションを構築およびコンテナ化するためのオープンソースのコンテナ化テクノロジーです。

**コードリポジトリ**

このパターンのコードは、GitHub [AWS IoT Greengrass v2 Docker-in-Docker ](https://github.com/aws-samples/aws-iot-greengrass-docker-in-docker)リポジトリで入手できます。

## エピック
<a name="deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container-epics"></a>

### AWS IoT Greengrass V2 Docker-in-Docker イメージを構築する
<a name="build-the-gg2-docker-in-docker-image"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| クローンを作成してリポジトリに移動します。 | リポジトリのクローンを作成するには、次のコマンドを使用します。`git clone https://github.com/aws-samples/aws-iot-greengrass-v2-docker-in-docker.git``docker` ディレクトリに移動するには、次のコマンドを使用します。`cd aws-iot-greengrass-v2-docker-in-docker/docker` | DevOps エンジニア、AWS DevOps | 
| Docker イメージを作成します。 | デフォルト (最新) バージョンで Docker イメージを構築するには、次のコマンドを実行します。`docker build -t x86_64/aws-iot-greengrass:latest .`または、特定のバージョンで Docker イメージを構築するには、次のコマンドを実行します。`docker build --build-arg GREENGRASS_RELEASE_VERSION=2.12.0 -t x86_64/aws-iot-greengrass:2.12.0 .`ビルドを確認するには、次のコマンドを実行します。`docker images \| grep aws-iot-greengrass`  | AWS DevOps、DevOps エンジニア | 
| (オプション) Amazon ECR にプッシュします。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html) | アプリ開発者、AWS DevOps、DevOps エンジニア | 

### AWS 認証情報を設定する
<a name="configure-aws-credentials"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| 認証方法を選択します。 | 以下のオプションのいずれかを選択してください。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html) | AWS 管理者 | 
| 認証方法を設定します。 | 選択した認証方法では、次の設定ガイダンスを使用します。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html) | AWS 管理者 | 

### Docker Compose で を実行する
<a name="run-with-docker-compose"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| `docker-compose.yml` を設定します。 | 次のように、 `docker-compose.yml` ファイルを環境変数で更新します。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html) | DevOps エンジニア | 
| コンテナを起動して検証します。 | フォアグラウンドで を開始するには、次のコマンドを実行します。`docker-compose up --build`または、バックグラウンドで開始するには、次のコマンドを実行します。`docker-compose up --build -d`ステータスを確認するには、次のコマンドを実行します。`docker-compose ps`ログをモニタリングするには、次のコマンドを実行します。`docker-compose logs -f` | DevOps エンジニア | 

### Docker CLI で を実行する
<a name="run-with-docker-cli"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| Docker CLI でコンテナを実行します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html) | DevOps エンジニア | 
| コンテナを確認します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html) | DevOps エンジニア | 

### コンテナ化されたアプリケーションの管理
<a name="manage-containerized-applications"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| アプリケーションをデプロイします。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html) | アプリ開発者 | 
| Docker-in-Docker にアクセスしてテストします。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html) | DevOps エンジニア | 

### (オプション) Amazon ECS Anywhere との統合
<a name="optional-integrate-with-ecs-anywhere"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| Amazon ECS クラスターをセットアップします。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html) | AWS 管理者 | 
| Amazon ECS タスクをデプロイします。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html) | AWS 管理者 | 

### 停止とクリーンアップ
<a name="stop-and-cleanup"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| コンテナを停止します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html) | DevOps エンジニア | 

## トラブルシューティング
<a name="deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container-troubleshooting"></a>


| 問題 | ソリューション | 
| --- | --- | 
| コンテナはアクセス許可エラーで開始できません。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)`--privileged` は、コンテナに拡張された権限を付与します。 | 
| プロビジョニングは認証情報エラーで失敗します。 | 認証情報が正しく設定されていることを確認するには、次の手順を実行します。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)IAM アクセス許可に `iot:CreateThing`、`iot:CreatePolicy`、、`iot:AttachPolicy``iam:CreateRole`、 が含まれていることを確認します`iam:AttachRolePolicy`。 | 
| コンテナ内の Docker デーモンに接続できません。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html) | 
| コンテナのディスク容量が不足しています。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)最小ディスク容量を確保する: 基本オペレーションの場合は 5 GB、 AWS IoT SiteWise Edge の場合は 50 GB | 
| ビルドの問題。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html) | 
| ネットワーク接続の問題。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)ファイアウォールがアウトバウンド HTTPS (443) および MQTT (8883) トラフィックを許可していることを確認します。 | 
| Greengrass コンポーネントはデプロイに失敗します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)`/greengrass/v2/logs/` ディレクトリのコンポーネント固有のログを確認します。 | 
| コンテナは起動直後に終了します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container.html)の場合、必要なすべての環境変数が正しく設定されていることを確認します`PROVISION=true`。コンテナの起動時に `--init`フラグが使用されていることを確認します。 | 

## 関連リソース
<a name="deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container-resources"></a>

**AWS リソース**
+ [Amazon Elastic Container Service](https://aws.amazon.com/ecs/)
+ [AWS IoT SiteWise モデルとアセットのエッジデータ処理を設定する](https://docs.aws.amazon.com/iot-sitewise/latest/userguide/edge-processing.html)
+ [とは AWS IoT Greengrass](https://docs.aws.amazon.com/greengrass/v2/developerguide/what-is-iot-greengrass.html)

**その他のリソース**
+ [Docker ドキュメント](https://docs.docker.com/)

## 追加情報
<a name="deploy-containerized-applications-on-aws-iot-greengrass-version-2-running-as-a-docker-container-additional"></a>
+  AWS IoT SiteWise Edge データ処理の場合、Docker は AWS IoT Greengrass 環境内で利用できる必要があります。
+ ネストされたコンテナを実行するには、管理者レベルの認証情報を使用して AWS IoT Greengrass コンテナを実行する必要があります。