この資料では、Docker for Windows を使って Windows OS 上で Linux ベースのアプリを開発する方法、そして Web アプリを含む Docker コンテナをクラウド環境(Azure 環境)に展開する方法について解説します。
※ 本資料では Docker の Linux コンテナのみを取り扱います。(Windows コンテナは取り扱いません。Windows OS で使い慣れたエディタや開発環境を使いつつ、Docker for Windows を活用して Linux 上でデバッグを行う、というシナリオを扱っています。)
※ 資料の概要は以下の blog エントリを参照してください。
https://blogs.msdn.microsoft.com/nakama/2018/09/27/dockerandazure/
DCSF19 Hardening Docker daemon with Rootless modeDocker, Inc.
Akihiro Suda, NTT Corporation
Docker CE 19.03 is going to support "Rootless mode", which allows running the entire Docker daemon and its dependencies as a non-root user on the host, so as to protect the host from malicious containers in a simple but very strong way.
Rootless mode is also attractive for users who cannot get `sudo` permission for installing Docker on shared computing machines. e.g. HPC users.
In this talk, Akihiro Suda, the author of the Rootless mode (PR: moby#38050), will explain how users can get started with Rootless mode.
He will also explain the implementation details of Rootless mode and planned enhancements such as LDAP integration.
DCSF19 Hardening Docker daemon with Rootless modeDocker, Inc.
Akihiro Suda, NTT Corporation
Docker CE 19.03 is going to support "Rootless mode", which allows running the entire Docker daemon and its dependencies as a non-root user on the host, so as to protect the host from malicious containers in a simple but very strong way.
Rootless mode is also attractive for users who cannot get `sudo` permission for installing Docker on shared computing machines. e.g. HPC users.
In this talk, Akihiro Suda, the author of the Rootless mode (PR: moby#38050), will explain how users can get started with Rootless mode.
He will also explain the implementation details of Rootless mode and planned enhancements such as LDAP integration.
9. p.9
Docker の基本的な特徴④ Docker for Windows による開発
◼ Docker for Windows を利用すると、Windows OS 上での Linux アプリの開発
が非常に容易に行える
Linux アプリを開発する際も、エディタやブラウザは Windows デスクトップを使った方
が便利
◼ コーディングは Windows 環境、動作確認は Linux 環境で行えれば便利
Docker for Windows をインストールすると、以下のような環境が構築される
◼ Hyper-V + Core OS (Docker Engine が組み込まれた軽量 Linux OS)
◼ Windows 用 docker コマンドラインツール
これらにより、Windows 上で実装したアプリを Hyper-V 上の Linux で動作確認できる
◼ Windows マシン 1 台で Linux アプリ開発ができるので便利!
開発用マシン
Hyper-V
Windows 10
CoreOS
Docker
Image
アプリケーション
(Java など)
STS
Chrome
VS Code
※ (参考)システム要件
• Windows 10 Pro または Enterprise
(Hyper-V が使えること)
• メモリは最低でも 8GB 以上を推奨
(Hyper-V 上の Linux の動作に必要
なメモリを確保するため)
10. p.10
Docker for Windows の基本的な利用方法
◼ Docker for Windows による基本的なコンテナ作成と実行の流れは以下の通り
1. アプリを作成する
2. Dockerfile によりイメージの作成手順を記述する
3. Docker イメージを作成する
4. Docker コンテナを開始する
5. Docker コンテナを終了し、後片付けをする
◼ 以下では、すでに開発済みの Java Spring Boot アプリを、以下の形で Docker
に載せて実行するケースを例に取って解説する
Windows OS 上で、STS (Spring Boot 用 Eclipse)を使ってコーディング
Linux OS 上の Java ランタイムを使ってアプリを実行
Windows OS 上の Chrome ブラウザから動作を確認する
11. p.11
Docker for Windows の基本的な利用方法
◼ 1. Docker 上に載せる Java アプリケーションの作成
(本資料では、開発済みの Spring Boot サンプルアプリを利用する)
開発されたサンプルアプリは、以下のコマンドラインにより起動することができる
◼ java -jar ./target/azrefarc-springboot-0.0.1-SNAPSHOT.jar
◼ (参考) Spring Boot アプリのパッケージには Web サーバが組み込まれており、コマン
ドラインから起動するとポート 8080 で呼び出すことが可能
◼ ※ この方法では、Windows 版の Java 上で Spring Boot アプリが動作している
ソースコード
コンパイル
Java パッケージファイル
(azrefarc-springboot-0.0.1-SNAPSHOT.jar)
java -jar ./target/azrefarc-
springboot-0.0.1-SNAPSHOT.jar
http://localhost:8080/ で
呼び出し
※(注意) この方法では、Windows
版の Java 上でアプリが動作している
14. p.14
Docker for Windows の基本的な利用方法
◼ 3. Docker イメージの作成
Dockerfile ファイルと docker コマンドラインツールを使って、Docker イメージを作成
◼ docker build -t <イメージ名> <Dockerfile へのパス>
◼ これにより、Windows OS 上で Linux のイメージファイルを作成することができる
◼ 初回実行時は Docker Hub からのイメージダウンロードに時間がかかる
作成されたイメージはローカルディスク上に保存される
◼ docker images コマンドにより確認できる
C:¥Users¥nakama¥source¥repos¥AzRefArc.SpringBoot>docker build -t myjavaapp .
Sending build context to Docker daemon 110.8MB
Step 1/4 : FROM openjdk:8-jdk-alpine
---> cc2179b8f042
Step 2/4 : COPY ./target/azrefarc-springboot-0.0.1-SNAPSHOT.jar /app/ROOT.jar
---> Using cache
---> e5d742024522
Step 3/4 : EXPOSE 8080
---> Using cache
---> 9fa6489ab147
Step 4/4 : CMD ["java", "-jar", "/app/ROOT.jar"]
---> Using cache
---> 137800a4d12c
Successfully built 137800a4d12c
Successfully tagged myjavaapp:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories
added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for
sensitive files and directories.
C:¥Users¥nakama¥source¥repos¥AzRefArc.SpringBoot>
コマンドライン
C:¥Users¥nakama¥source¥repos¥AzRefArc.SpringBoot>docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myjavaapp latest 137800a4d12c 12 hours ago 170MB
openjdk 8-jdk-alpine cc2179b8f042 13 days ago 102MB
作成されたイメージファイル
• 無指定の場合、自動的に "latest" タグが付与される
• このため、正式名は "myjavaapp:latest" となる
42. p.42
オーケストレーション技術の必要性
◼ Kubernetes と Web Apps for Containers の違いについて
Kubernetes は POD と呼ばれる単位で複数のサービスを一括展開できる
◼ このため、MSA (マイクロサービスアーキテクチャ)ベースで設計されたマイクロサービ
スを一括して配置していくことができる(→ 次ページ参照)
Azure Web Apps for Containers は、ロードバランサ + クラスタ化された Docker コン
テナを構成することしかできない
◼ Web-DB 型システムにおける Web 部のように、物理 1 階層分の配置しかできない
◼ このため、必要となる予備知識がほとんどなく、すぐさまシンプルに使うことができる
出典) https://github.com/kubernetes/kubernetes/blob/release-
1.3/docs/design/architecture.md
ロード
バランサ
http://app-a.azurewebsites.net/
http://app-b.azurewebsites.net/
B
A
A
B
B A
Web Apps for
Containers
共用
C
C
C
D
D
D
Docker アプリ
を配置可能
ロードバランサ
によるルーティン
グと負荷分散
Kubernetes (AKS, EKS など) Azure Web Apps for Containers
複数のサービ
スでインフラを
共用できる