Google Cloud Platform Japan Blog

最新情報や使い方、チュートリアル、国内外の事例やイベントについてお伝えします。

Docker を使って ASP.NET Core アプリを App Engine で実行する

2016年10月13日木曜日
アプリを “DemoFlexApp” という名前で Visual Studio のデフォルトの “Projects” ディレクトリに保存します。次のダイアログで “Web Application” を選択し、“OK” をクリックします。

これでアプリが生成されます。F5 キーを押してローカルで試してみましょう。アプリがビルドされ、実行されてブラウザ ウィンドウに表示されます。表示されたらブラウザを閉じ、デバッグ セッションを停止して、アプリを停止します。

ステップ 2 : Docker コンテナとしてパッケージ

次のステップでは、作成したアプリを App Engine flexible で実行する準備をしましょう。最初に、コンテナとその内容を定義します。Docker をインストールする必要はありませんので、ご心配なく。App Engine flexible はデプロイ プロセスの一環として、Docker イメージをリモートでビルドしてくれます。

ここではコマンドラインから作業します。“Windows” キーを押しながら “R” キーを押し、ダイアログで “cmd.exe” とタイプして、新しいコマンドライン ウィンドウを開きます。

そして、ステップ 1 で作成したプロジェクトを含むディレクトリに移動してください。プロジェクトのパスを取得するには、Visual Studio のソリューション エクスプローラーでプロジェクトを右クリックし、“Open Folder in File Explorer(エクスプローラーでフォルダーを開く)” オプションを選びます。

エクスプローラー ウィンドウからプロジェクトのパスをコピーし、コマンドライン ウィンドウに貼り付けます。

まず、アプリの Docker イメージの内容を 1 つのディレクトリに作成します。ディレクトリの中には、アプリのすべてのパッケージ、ページ、クライアント サイド スクリプトが含まれます。.NET CLI がこのディレクトリを作成し、アプリを “発行” します。そのためのコマンドは次のとおりです。
dotnet publish -c Release
アプリは Release 構成でデフォルトの publish ディレクトリに発行されます。アプリの発行プロセスでは .NET CLI がすべての依存関係を解決し、他のすべてのファイルも含めてこの “発行先” ディレクトリにまとめます。ちなみに、このディレクトリのことを Microsoft は .NET Core Portable App と呼んでいます。

発行先ディレクトリは、アプリを構成するすべてのファイルを含み、.NET Core がサポートするあらゆるプラットフォームでアプリを実行するのに利用できます。以下のコマンドにより、このディレクトリからアプリを実行できます。
cd bin\Release\netcoreapp1.0\publish
dotnet DemoFlexApp.dll

このコマンドを実行するときは、すべてのリソースが見つかるように、必ず発行先ディレクトリをカレント ディレクトリにしておきます。

コンテナとその内容を定義したら、次の作業は App Engine flexible にデプロイするアプリを構成することです。そのためには以下の 2 つのファイルが必要になります。
  • Dockerfile : アプリ ファイルを Docker コンテナにパッケージする方法を記述します。
  • app.yaml : Google Cloud SDK ツールにアプリのデプロイ方法を知らせます。
アプリのデプロイは、上で作成した発行先ディレクトリから行うことになります。

発行先ディレクトリに “Dockerfile” という空のファイルを作成し、以下の行をコピーして貼り付け、保存します。

FROM microsoft/dotnet:1.0.1-core
COPY . /app
WORKDIR /app
EXPOSE 8080
ENV ASPNETCORE_URLS=http://*:8080
ENTRYPOINT ["dotnet", "DemoFlexApp.dll"]
Dockerfile は、Docker イメージの内容を記述したものです。まず既存イメージを指定し、続いてファイルの追加など、既存イメージに対する変更を記述していきます。

私たちのリポジトリの Dockerfile では、最初に Microsoft の公式イメージを指定します。このイメージは、.NET Core アプリを実行するようにあらかじめ構成されています。さらに、このディレクトリからアプリを実行するのに必要なアプリ ファイルやツールを追加しています。

この Dockerfile に含まれる 1 つの重要な構成が、アプリが受信トラフィックをリッスンするポートを、App Engine flexible の要件に従って 8080 に設定していることです。これは、環境変数 ASPNETCORE_URLS で設定されています。ASP.NET Core アプリはこの環境変数を使って、リッスンするポートを決めています。

一方、app.yaml は、アプリを App Engine(今回は App Engine flexible)にデプロイする方法を記述したものです。以下は、アプリを App Engine flexible で実行するうえで必要最小限の app.yaml ファイルです。カスタム ランタイムと flexible environment を指定しています。

発行先ディレクトリに “app.yaml” という新しいファイルを作成し、以下の内容をコピーして貼り付け、保存します。
runtime: custom
vm: true

ステップ 3 : App Engine flexible にデプロイ

Dockerfile と app.yaml を発行先ディレクトリに保存したら、アプリを App Engine flexible にデプロイする準備は完了です。

アプリのデプロイには Google Cloud SDK を使います。こちらの手順に従って Google Cloud SDK をマシンに完全にセットアップしてください。課金を有効にした Google Cloud Platform プロジェクトも必要になります。

アプリを構成し、アプリをデプロイするプロジェクトを選択したら、いよいよ App Engine flexible へのデプロイです。デプロイするには以下のコマンドを実行します。
gcloud app deploy app.yaml
このコマンドは、完了するまでしばらく時間がかかります。最初は特にそうです。すべてのセットアップを実行しなければならないからです。コマンドが完了したら、新たにデプロイされたアプリをブラウザで表示してみましょう。
gcloud app browse
表示されましたね! 以上で完了です。ASP.NET Core アプリを Docker コンテナにパッケージし、App Engine flexible にデプロイしてみました。多くの ASP.NET アプリが App Engine で実行されることを、私たちは楽しみにしています。


* この投稿は米国時間 10 月 5 日、Software Developer である Ivan Naranjo によって投稿されたもの(投稿はこちら)の抄訳です。

- Posted by Ivan Naranjo, Software Developer
Share on Twitter Share on Facebook

Google
ラベル: .NET , .NET Core ランタイム , App Engine , App Engine flexible , Bower , Cloud API , Cloud Machine Learning , cloud Pub/Sub , Dockerfile , Flexible Environment , NuGet パッケージ
  

12 か月間のトライアル

12 か月間のトライアル
300 ドル相当が無料になるトライアルで、あらゆる GCP プロダクトをお試しいただけます。

Labels


  • .NET
  • .NET Core
  • .NET Core ランタイム
  • .NET Foundation
  • #gc_inside
  • #gc-inside
  • #GoogleCloudSummit
  • #GoogleNext18
  • #GoogleNext19
  • #inevitableja
  • Access Management
  • Access Transparency
  • Advanced Solutions Lab
  • AI
  • AI Hub
  • AlphaGo
  • Ansible
  • Anthos
  • Anvato
  • Apache Beam
  • Apache Maven
  • Apache Spark
  • API
  • Apigee
  • APIs Explore
  • App Engine
  • App Engine Flex
  • App Engine flexible
  • AppArmor
  • AppEngine
  • AppScale
  • AprilFool
  • AR
  • Artifactory
  • ASL
  • ASP.NET
  • ASP.NET Core
  • Attunity
  • AutoML Vision
  • AWS
  • Big Data
  • Big Data NoSQL
  • BigQuery
  • BigQuery Data Transfer Service
  • BigQuery GIS
  • Billing Alerts
  • Bime by Zendesk
  • Bitbucket
  • Borg
  • BOSH Google CPI
  • Bower
  • bq_sushi
  • BreezoMeter
  • BYOSL
  • Capacitor
  • Chromium OS
  • Client Libraries
  • Cloud API
  • Cloud Armor
  • Cloud Audit Logging
  • Cloud AutoML
  • Cloud Bigtable
  • Cloud Billing Catalog API
  • Cloud Billing reports
  • Cloud CDN
  • Cloud Client Libraries
  • Cloud Console
  • Cloud Consoleアプリ
  • Cloud Container Builder
  • Cloud Dataflow
  • Cloud Dataflow SDK
  • Cloud Datalab
  • Cloud Dataprep
  • Cloud Dataproc
  • Cloud Datastore
  • Cloud Debugger
  • Cloud Deployment Manager
  • Cloud Endpoints
  • Cloud Firestore
  • Cloud Foundry
  • Cloud Foundry Foundation
  • Cloud Functions
  • Cloud Healthcare API
  • Cloud HSM
  • Cloud IAM
  • Cloud IAP
  • Cloud Identity
  • Cloud IoT Core
  • Cloud Jobs API
  • Cloud KMS
  • Cloud Launcher
  • Cloud Load Balancing
  • Cloud Machine Learning
  • Cloud Memorystore
  • Cloud Memorystore for Redis
  • Cloud monitoring
  • Cloud NAT
  • Cloud Natural Language API
  • Cloud Networking
  • Cloud OnAir
  • Cloud OnBoard
  • cloud Pub/Sub
  • Cloud Resource Manager
  • Cloud Resource Manager API
  • Cloud SCC
  • Cloud SDK
  • Cloud SDK for Windows
  • Cloud Security Command Center
  • Cloud Services Platform
  • Cloud Source Repositories
  • Cloud Spanner
  • Cloud Speech API
  • Cloud Speech-to-Text
  • Cloud SQL
  • Cloud Storage
  • Cloud Storage FUSE
  • Cloud Tools for PowerShell
  • Cloud Tools PowerShell
  • Cloud TPU
  • Cloud Translation
  • Cloud Translation API
  • Cloud Virtual Network
  • Cloud Vision
  • Cloud VPC
  • CloudBerry Backup
  • CloudBerry Lab
  • CloudConnect
  • CloudEndure
  • Cloudflare
  • Cloudian
  • CloudML
  • Cluster Federation
  • Codefresh
  • Codelabs
  • Cohesity
  • Coldline
  • Colossus
  • Compute Engine
  • Compute user Accounts
  • Container Engine
  • Container Registry
  • Container-Optimized OS
  • Container-VM Image
  • Couchbase
  • Coursera
  • CRE
  • CSEK
  • Customer Reliability Engineering
  • Data Studio
  • Databases
  • Dbvisit
  • DDoS
  • Debugger
  • Dedicated Interconnect
  • deep learning
  • Deployment Manager
  • Developer Console
  • Developers
  • DevOps
  • Dialogflow
  • Disney
  • DLP API
  • Docker
  • Dockerfile
  • Drain
  • Dreamel
  • Eclipse
  • Eclipse Orion
  • Education Grants
  • Elasticsearch
  • Elastifile
  • Energy Sciences Network
  • Error Reporting
  • ESNet
  • Evernote
  • FASTER
  • Fastly
  • Firebase
  • Firebase Analytics
  • Firebase Authentication
  • Flexible Environment
  • Forseti Security
  • G Suite
  • Gartner
  • gcloud
  • GCP
  • GCP Census
  • GCP 移行ガイド
  • GCP 認定資格チャレンジ
  • GCPUG
  • GCP導入事例
  • gcsfuse
  • GEO
  • GitHub
  • GitLab
  • GKE
  • Go
  • Go 言語
  • Google App Engine
  • Google Apps
  • Google Certified Professional - Data Engineer
  • Google Cloud
  • Google Cloud Certification Program
  • Google Cloud Client Libraries
  • Google Cloud Console
  • Google Cloud Dataflow
  • Google Cloud Datalab
  • Google Cloud Datastore
  • Google Cloud Endpoints
  • Google Cloud Explorer
  • Google Cloud Identity and Access Management
  • Google Cloud INSIDE
  • Google Cloud INSIDE Digital
  • Google Cloud INSIDE FinTech
  • Google Cloud Interconnect
  • Google Cloud Launcher
  • Google Cloud Logging
  • Google Cloud Next '18 in Tokyo
  • Google Cloud Next '19 in Tokyo
  • Google Cloud Platform
  • Google Cloud Resource Manager
  • Google Cloud Security Scanner
  • Google Cloud Shell
  • Google Cloud SQL
  • Google Cloud Storage
  • Google Cloud Storage Nearline
  • Google Cloud Summit '18
  • Google Cloud Summit ’18
  • Google Cloud Tools for IntelliJ
  • Google Code
  • Google Compute Engine
  • Google Container Engine
  • Google Data Analytics
  • Google Data Studio
  • Google Date Studio
  • Google Deployment Manager
  • Google Drive
  • Google Earth Engine
  • Google Genomics
  • Google Kubernetes Engine
  • Google maps
  • google maps api
  • Google Maps APIs
  • Google Maps Platform
  • Google SafeSearch
  • Google Service Control
  • Google Sheets
  • Google Slides
  • Google Translate
  • Google Trust Services
  • Google VPC
  • Google マップ
  • Google 公認プロフェッショナル
  • GoogleNext18
  • GPU
  • Gradle
  • Grafeas
  • GroupBy
  • gRPC
  • HA / DR
  • Haskell
  • HEPCloud
  • HIPAA
  • Horizon
  • HTCondor
  • IaaS
  • IAM
  • IBM
  • IBM POWER9
  • icon
  • IERS
  • Improbable
  • INEVITABLE ja night
  • inevitableja
  • InShorts
  • Intel
  • IntelliJ
  • Internal Load Balancing
  • Internet2
  • IoT
  • Issue Tracker
  • Java
  • Jenkins
  • JFrog
  • JFrog Artifactory SaaS
  • Jupiter
  • Jupyter
  • Kaggle
  • Kayenta
  • Khan Academy
  • Knative
  • Komprise
  • kubefed
  • Kubeflow Pipelines
  • Kubernetes
  • KVM
  • Landsat
  • load shedding
  • Local SSD
  • Logging
  • Looker
  • Machine Learning
  • Magenta
  • Managed Instance Group
  • Managed Instance Group Updater
  • Maps API
  • Maps-sensei
  • Mapsコーナー
  • Maven
  • Maxon Cinema 4D
  • MightyTV
  • Mission Control
  • MongoDB
  • MQTT
  • Multiplay
  • MySQL
  • Nearline
  • Network Time Protocol
  • Networking
  • neural networks
  • Next
  • Node
  • NoSQL
  • NTP
  • NuGet パッケージ
  • OCP
  • OLDISM
  • Open Compute Project
  • OpenCAPI
  • OpenCAPI Consortium
  • OpenShift Dedicated
  • Orbitera
  • Organization
  • Orion
  • Osaka
  • Paas
  • Panda
  • Particle
  • Partner Interconnect
  • Percona
  • Pete's Dragon
  • Pivotal
  • Pivotal Cloud Foundry
  • PLCN
  • Podcast
  • Pokemon GO
  • Pokémon GO
  • Poseidon
  • Postgre
  • PowerPoint
  • PowerShell
  • Professional Cloud Network Engineer
  • Protocol Buffers
  • Puppet
  • Pythian
  • Python
  • Qwiklabs
  • Rails
  • Raspberry Pi
  • Red Hat
  • Redis
  • Regional Managed Instance Groups
  • Ruby
  • Rust
  • SAP
  • SAP Cloud Platform
  • SC16
  • ScaleArc
  • Secure LDAP
  • Security & Identity
  • Sentinel-2
  • Service Broker
  • Serving Websites
  • Shared VPC
  • SideFX Houdini
  • SIGOPS Hall of Fame Award
  • Sinatra
  • Site Reliability Engineering
  • Skaffold
  • SLA
  • Slack
  • SLI
  • SLO
  • Slurm
  • Snap
  • Spaceknow
  • SpatialOS
  • Spinnaker
  • Spring
  • SQL Server
  • SRE
  • SSL policies
  • Stack Overflow
  • Stackdriver
  • Stackdriver Agent
  • Stackdriver APM
  • Stackdriver Debugger
  • Stackdriver Diagnostics
  • Stackdriver Error Reporting
  • Stackdriver Logging
  • Stackdriver Monitoring
  • Stackdriver Trace
  • Stanford
  • Startups
  • StatefulSets
  • Storage & Databases
  • StorReduce
  • Streak
  • Sureline
  • Sysbench
  • Tableau
  • Talend
  • Tensor Flow
  • Tensor Processing Unit
  • TensorFlow
  • Terraform
  • The Carousel
  • TPU
  • Trace
  • Transfer Appliance
  • Transfer Service
  • Translate API
  • Uber
  • Velostrata
  • Veritas
  • Video Intelligence API
  • Vision API
  • Visual Studio
  • Visualization
  • Vitess
  • VM
  • VM Image
  • VPC Flow Logs
  • VR
  • VSS
  • Waze
  • Weave Cloud
  • Web Risk AP
  • Webyog
  • Wide and Deep
  • Windows Server
  • Windows ワークロード
  • Wix
  • Worlds Adrift
  • Xplenty
  • Yellowfin
  • YouTube
  • Zaius
  • Zaius P9 Server
  • Zipkin
  • ZYNC Render
  • アーキテクチャ図
  • イベント
  • エラーバジェット
  • エンティティ
  • オンライン教育
  • クラウド アーキテクト
  • クラウド移行
  • グローバル ネットワーク
  • ゲーム
  • コードラボ
  • コミュニティ
  • コンテスト
  • コンピューティング
  • サーバーレス
  • サービス アカウント
  • サポート
  • ジッター
  • ショート動画シリーズ
  • スタートガイド
  • ストレージ
  • セキュリティ
  • セミナー
  • ソリューション ガイド
  • ソリューション: メディア
  • データ エンジニア
  • データセンター
  • デベロッパー
  • パートナーシップ
  • ビッグデータ
  • ファジング
  • プリエンプティブル GPU
  • プリエンプティブル VM
  • フルマネージド
  • ヘルスケア
  • ホワイトペーパー
  • マイクロサービス
  • まっぷす先生
  • マルチクラウド
  • リージョン
  • ロード シェディング
  • 運用管理
  • 可用性
  • 海底ケーブル
  • 機械学習
  • 金融
  • 継続的デリバリ
  • 月刊ニュース
  • 資格、認定
  • 新機能、アップデート
  • 深層学習
  • 深層強化学習
  • 人気記事ランキング
  • 内部負荷分散
  • 認定試験
  • 認定資格
  • 料金


Archive


  •     2019
    • 8月
    • 7月
    • 6月
    • 5月
    • 4月
    • 3月
    • 2月
    • 1月
  •     2018
    • 12月
    • 11月
    • 10月
    • 9月
    • 8月
    • 7月
    • 6月
    • 5月
    • 4月
    • 3月
    • 2月
    • 1月
  •     2017
    • 12月
    • 11月
    • 10月
    • 9月
    • 8月
    • 7月
    • 6月
    • 5月
    • 4月
    • 3月
    • 2月
    • 1月
  •     2016
    • 12月
    • 11月
    • 10月
    • 9月
    • 8月
    • 7月
    • 6月
    • 5月
    • 4月
    • 3月
    • 2月
    • 1月
  •     2015
    • 12月
    • 11月
    • 10月
    • 9月
    • 8月
    • 7月
    • 6月
    • 5月
    • 4月
    • 3月
    • 2月
    • 1月
  •     2014
    • 12月
    • 11月
    • 10月
    • 9月
    • 8月
    • 6月
    • 5月
    • 4月
    • 3月
    • 2月

Feed

月刊ニュースレターに登録
新着ポストをメールで受け取る

Company-wide

  • Google 公式ブログ 日本版
  • Google 公式ブログ 英語版

製品・サービス

  • Google Cloud Japan 公式ブログ
  • Google AdWords 日本版 公式ブログ
  • Google Webmaster Central 日本版 公式ブログ

デベロッパー

  • Google Developer Relations 日本版 公式ブログ
  • Google
  • Privacy
  • Terms