Copyright © 2013 by S-cubism Inc. All rights reserved. 1PageCopyright © 2016 by S-cubism Inc. All rights reserved.
Dockerを用いた
マイクロサービスについて
株式会社エスキュービズム
Copyright © 2013 by S-cubism Inc. All rights reserved. 2PageCopyright © 2016 by S-cubism Inc. All rights reserved.
モチベーション
Copyright © 2013 by S-cubism Inc. All rights reserved. 3PageCopyright © 2016 by S-cubism Inc. All rights reserved.
コードの肥大化
機能開発
コード修正のコスト増大
開発の普遍的課題
Copyright © 2013 by S-cubism Inc. All rights reserved. 4PageCopyright © 2016 by S-cubism Inc. All rights reserved.
オブジェクト指向
ライブラリ化
マイクロサービス
モジュール化の粒度
Copyright © 2013 by S-cubism Inc. All rights reserved. 5PageCopyright © 2016 by S-cubism Inc. All rights reserved.
https://www.nginx.com/blog/building-
microservices-using-an-api-gateway/
求められる多様性と専門性
Copyright © 2016 by S-cubism Inc. All rights reserved. 6Page
https://www.nginx.com/blog/building-
microservices-using-an-api-gateway/
マイクロサービス
自律分散システム
Copyright © 2016 by S-cubism Inc. All rights reserved. 7Page
多様性と専門性の実現
マイクロ
サービス
アプリ
マイクロ
サービス
マイクロ
サービス
アプリ アプリ
Copyright © 2016 by S-cubism Inc. All rights reserved. 8Pagehttp://wing.vc/blog/microservices-containers-and-the-digital-dialectic
時代の変遷
Copyright © 2013 by S-cubism Inc. All rights reserved. 9PageCopyright © 2016 by S-cubism Inc. All rights reserved.
マイクロサービスによる
メリットとコスト
時代
トレードオフ
Copyright © 2013 by S-cubism Inc. All rights reserved. 10PageCopyright © 2016 by S-cubism Inc. All rights reserved.
マイクロサービスの
実現方法
Copyright © 2013 by S-cubism Inc. All rights reserved. 11PageCopyright © 2016 by S-cubism Inc. All rights reserved.
Dockerの利用
https://www.nginx.com/blog/building-
microservices-using-an-api-gateway/
Copyright © 2013 by S-cubism Inc. All rights reserved. 12PageCopyright © 2016 by S-cubism Inc. All rights reserved.
https://www.datadoghq.com/blog/docker-
performance-datadog/
Dockerの構造
旧来の方法 Docker
Copyright © 2013 by S-cubism Inc. All rights reserved. 13PageCopyright © 2016 by S-cubism Inc. All rights reserved.
Dockerの基本操作
イメージの作成
$ docker pull ubuntu:latest
latest: Pulling from library/ubuntu
92ec6d044cb3: Pull complete
2ef91804894a: Pull complete
f80999a1f330: Pull complete
6cc0fc2a5ee3: Pull complete
Digest:
sha256:457b05828bdb5dcc044d93d042863fba3f2158ae249a6db5ae3934307c757c54
Status: Downloaded newer image for ubuntu:latest
イメージの確認
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest 6cc0fc2a5ee3 7 days ago 187.9 MB
Copyright © 2013 by S-cubism Inc. All rights reserved. 14PageCopyright © 2016 by S-cubism Inc. All rights reserved.
コンテナの作成
Dockerの基本操作
$ docker run -d ubuntu:latest sleep 10000
6293b06f5a14fe73d6bf25618e531238c0412cccad03295fa846be714b865c73
sleep 10000 → このコンテナで実行するコマンド
-d → バックグラウンドでコマンドを実行
コンテナの確認
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
6293b06f5a14 ubuntu:latest "sleep 10000" 7 minutes ago Up 7 minutes
romantic_lichterman
Copyright © 2013 by S-cubism Inc. All rights reserved. 15PageCopyright © 2016 by S-cubism Inc. All rights reserved.
コンテナにログイン
Dockerの基本操作
$ docker exec -it 6293b06f5a14 bash
root@6293b06f5a14:/#
コンテナの保存
root@6293b06f5a14:/# touch /tmp/test
root@6293b06f5a14:/# exit
$ docker commit 6293b06f5a14 ubuntu:modified1.0
a721df2cebafb0c84bae872cc7e3d3b3552e459180e4e221a97114441d38fb7f
[vagrant@localhost vagrant]$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu modified1.0 a721df2cebaf 4 seconds ago 187.9 MB
ubuntu latest 6cc0fc2a5ee3 7 days ago 187.9 MB
bash → 実行するシェルコマンド
-it → インタラクティブモードで実行
← コンテナの変更
← イメージの確認
Copyright © 2013 by S-cubism Inc. All rights reserved. 16PageCopyright © 2016 by S-cubism Inc. All rights reserved.
FROM ubuntu:latest
ENV foo /bar
WORKDIR ${foo}
ADD . $foo
Dockerfile
Dockerfileを作成
$ docker build .
Sending build context to Docker daemon 2.56 kB
Step 1 : FROM ubuntu:latest
---> 6cc0fc2a5ee3
Step 2 : ENV foo /bar
---> Running in 0eaced662f9d
---> c2bf16851a4d
Removing intermediate container 0eaced662f9d
Step 3 : WORKDIR ${foo}
---> Running in fb6f0cdc21c4
---> adbd809f4617
Removing intermediate container fb6f0cdc21c4
Step 4 : ADD . $foo
---> 16170c006078
Removing intermediate container 5eef5aeaf19a
Successfully built 16170c006078
Dockerfileからイメージを作成
$ vi Dockerfile
Copyright © 2013 by S-cubism Inc. All rights reserved. 17PageCopyright © 2016 by S-cubism Inc. All rights reserved.
Docker Volume
Copyright © 2013 by S-cubism Inc. All rights reserved. 18PageCopyright © 2016 by S-cubism Inc. All rights reserved.
Docker Networking
https://getcarina.com/docs/concept
s/docker-networking-basics/
Copyright © 2013 by S-cubism Inc. All rights reserved. 19PageCopyright © 2016 by S-cubism Inc. All rights reserved.
Docker Compose
Copyright © 2013 by S-cubism Inc. All rights reserved. 20PageCopyright © 2016 by S-cubism Inc. All rights reserved.
Docker Swarm
https://github.com/denverdino/aliyungo/wiki/D
ocker-Swarm-on-Aliyun
Copyright © 2013 by S-cubism Inc. All rights reserved. 21PageCopyright © 2016 by S-cubism Inc. All rights reserved.
マイクロサービスの
注意点
Copyright © 2013 by S-cubism Inc. All rights reserved. 22PageCopyright © 2016 by S-cubism Inc. All rights reserved.
コンテナ間をまたいでの
トランザクションは難しい
トランザクション
→ 結果整合性を実現する
→ 2相コミット(厳密には成り立たない)
Copyright © 2013 by S-cubism Inc. All rights reserved. 23PageCopyright © 2016 by S-cubism Inc. All rights reserved.
認証付きAPIゲートウェイ
http://microservices.io/patterns/apigateway.html
https://github.com/bitly/oauth2_proxy
Copyright © 2013 by S-cubism Inc. All rights reserved. 24PageCopyright © 2016 by S-cubism Inc. All rights reserved.
ロギング
http://www.fluentd.org/guides/re
cipes/docker-logging
RUN ln -sf /dev/stdout /var/log/nginx/access.log
RUN ln -sf /dev/stderr /var/log/nginx/error.log
Dockerfile:
Copyright © 2016 by S-cubism Inc. All rights reserved. 25Page
組織もマイクロ化する
Copyright © 2016 by S-cubism Inc. All rights reserved. 26Page
以上です。

Dockerを用いたマイクロサービスについて

  • 1.
    Copyright © 2013by S-cubism Inc. All rights reserved. 1PageCopyright © 2016 by S-cubism Inc. All rights reserved. Dockerを用いた マイクロサービスについて 株式会社エスキュービズム
  • 2.
    Copyright © 2013by S-cubism Inc. All rights reserved. 2PageCopyright © 2016 by S-cubism Inc. All rights reserved. モチベーション
  • 3.
    Copyright © 2013by S-cubism Inc. All rights reserved. 3PageCopyright © 2016 by S-cubism Inc. All rights reserved. コードの肥大化 機能開発 コード修正のコスト増大 開発の普遍的課題
  • 4.
    Copyright © 2013by S-cubism Inc. All rights reserved. 4PageCopyright © 2016 by S-cubism Inc. All rights reserved. オブジェクト指向 ライブラリ化 マイクロサービス モジュール化の粒度
  • 5.
    Copyright © 2013by S-cubism Inc. All rights reserved. 5PageCopyright © 2016 by S-cubism Inc. All rights reserved. https://www.nginx.com/blog/building- microservices-using-an-api-gateway/ 求められる多様性と専門性
  • 6.
    Copyright © 2016by S-cubism Inc. All rights reserved. 6Page https://www.nginx.com/blog/building- microservices-using-an-api-gateway/ マイクロサービス 自律分散システム
  • 7.
    Copyright © 2016by S-cubism Inc. All rights reserved. 7Page 多様性と専門性の実現 マイクロ サービス アプリ マイクロ サービス マイクロ サービス アプリ アプリ
  • 8.
    Copyright © 2016by S-cubism Inc. All rights reserved. 8Pagehttp://wing.vc/blog/microservices-containers-and-the-digital-dialectic 時代の変遷
  • 9.
    Copyright © 2013by S-cubism Inc. All rights reserved. 9PageCopyright © 2016 by S-cubism Inc. All rights reserved. マイクロサービスによる メリットとコスト 時代 トレードオフ
  • 10.
    Copyright © 2013by S-cubism Inc. All rights reserved. 10PageCopyright © 2016 by S-cubism Inc. All rights reserved. マイクロサービスの 実現方法
  • 11.
    Copyright © 2013by S-cubism Inc. All rights reserved. 11PageCopyright © 2016 by S-cubism Inc. All rights reserved. Dockerの利用 https://www.nginx.com/blog/building- microservices-using-an-api-gateway/
  • 12.
    Copyright © 2013by S-cubism Inc. All rights reserved. 12PageCopyright © 2016 by S-cubism Inc. All rights reserved. https://www.datadoghq.com/blog/docker- performance-datadog/ Dockerの構造 旧来の方法 Docker
  • 13.
    Copyright © 2013by S-cubism Inc. All rights reserved. 13PageCopyright © 2016 by S-cubism Inc. All rights reserved. Dockerの基本操作 イメージの作成 $ docker pull ubuntu:latest latest: Pulling from library/ubuntu 92ec6d044cb3: Pull complete 2ef91804894a: Pull complete f80999a1f330: Pull complete 6cc0fc2a5ee3: Pull complete Digest: sha256:457b05828bdb5dcc044d93d042863fba3f2158ae249a6db5ae3934307c757c54 Status: Downloaded newer image for ubuntu:latest イメージの確認 $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu latest 6cc0fc2a5ee3 7 days ago 187.9 MB
  • 14.
    Copyright © 2013by S-cubism Inc. All rights reserved. 14PageCopyright © 2016 by S-cubism Inc. All rights reserved. コンテナの作成 Dockerの基本操作 $ docker run -d ubuntu:latest sleep 10000 6293b06f5a14fe73d6bf25618e531238c0412cccad03295fa846be714b865c73 sleep 10000 → このコンテナで実行するコマンド -d → バックグラウンドでコマンドを実行 コンテナの確認 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6293b06f5a14 ubuntu:latest "sleep 10000" 7 minutes ago Up 7 minutes romantic_lichterman
  • 15.
    Copyright © 2013by S-cubism Inc. All rights reserved. 15PageCopyright © 2016 by S-cubism Inc. All rights reserved. コンテナにログイン Dockerの基本操作 $ docker exec -it 6293b06f5a14 bash root@6293b06f5a14:/# コンテナの保存 root@6293b06f5a14:/# touch /tmp/test root@6293b06f5a14:/# exit $ docker commit 6293b06f5a14 ubuntu:modified1.0 a721df2cebafb0c84bae872cc7e3d3b3552e459180e4e221a97114441d38fb7f [vagrant@localhost vagrant]$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu modified1.0 a721df2cebaf 4 seconds ago 187.9 MB ubuntu latest 6cc0fc2a5ee3 7 days ago 187.9 MB bash → 実行するシェルコマンド -it → インタラクティブモードで実行 ← コンテナの変更 ← イメージの確認
  • 16.
    Copyright © 2013by S-cubism Inc. All rights reserved. 16PageCopyright © 2016 by S-cubism Inc. All rights reserved. FROM ubuntu:latest ENV foo /bar WORKDIR ${foo} ADD . $foo Dockerfile Dockerfileを作成 $ docker build . Sending build context to Docker daemon 2.56 kB Step 1 : FROM ubuntu:latest ---> 6cc0fc2a5ee3 Step 2 : ENV foo /bar ---> Running in 0eaced662f9d ---> c2bf16851a4d Removing intermediate container 0eaced662f9d Step 3 : WORKDIR ${foo} ---> Running in fb6f0cdc21c4 ---> adbd809f4617 Removing intermediate container fb6f0cdc21c4 Step 4 : ADD . $foo ---> 16170c006078 Removing intermediate container 5eef5aeaf19a Successfully built 16170c006078 Dockerfileからイメージを作成 $ vi Dockerfile
  • 17.
    Copyright © 2013by S-cubism Inc. All rights reserved. 17PageCopyright © 2016 by S-cubism Inc. All rights reserved. Docker Volume
  • 18.
    Copyright © 2013by S-cubism Inc. All rights reserved. 18PageCopyright © 2016 by S-cubism Inc. All rights reserved. Docker Networking https://getcarina.com/docs/concept s/docker-networking-basics/
  • 19.
    Copyright © 2013by S-cubism Inc. All rights reserved. 19PageCopyright © 2016 by S-cubism Inc. All rights reserved. Docker Compose
  • 20.
    Copyright © 2013by S-cubism Inc. All rights reserved. 20PageCopyright © 2016 by S-cubism Inc. All rights reserved. Docker Swarm https://github.com/denverdino/aliyungo/wiki/D ocker-Swarm-on-Aliyun
  • 21.
    Copyright © 2013by S-cubism Inc. All rights reserved. 21PageCopyright © 2016 by S-cubism Inc. All rights reserved. マイクロサービスの 注意点
  • 22.
    Copyright © 2013by S-cubism Inc. All rights reserved. 22PageCopyright © 2016 by S-cubism Inc. All rights reserved. コンテナ間をまたいでの トランザクションは難しい トランザクション → 結果整合性を実現する → 2相コミット(厳密には成り立たない)
  • 23.
    Copyright © 2013by S-cubism Inc. All rights reserved. 23PageCopyright © 2016 by S-cubism Inc. All rights reserved. 認証付きAPIゲートウェイ http://microservices.io/patterns/apigateway.html https://github.com/bitly/oauth2_proxy
  • 24.
    Copyright © 2013by S-cubism Inc. All rights reserved. 24PageCopyright © 2016 by S-cubism Inc. All rights reserved. ロギング http://www.fluentd.org/guides/re cipes/docker-logging RUN ln -sf /dev/stdout /var/log/nginx/access.log RUN ln -sf /dev/stderr /var/log/nginx/error.log Dockerfile:
  • 25.
    Copyright © 2016by S-cubism Inc. All rights reserved. 25Page 組織もマイクロ化する
  • 26.
    Copyright © 2016by S-cubism Inc. All rights reserved. 26Page 以上です。