Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Docker 入門
Search
airhand
July 03, 2018
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Docker 入門
docker 概念とチュートリアル
airhand
July 03, 2018
More Decks by airhand
See All by airhand
JS Framework入門(2018)
airhand
0
83
ansible入門
airhand
0
260
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
55
8.4k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
260
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
Navigating Weather and Climate Data
rabernat
0
560
A Modern Web Designer's Workflow
chriscoyier
699
190k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
540
HDC tutorial
michielstock
2
960
How to Ace a Technical Interview
jacobian
280
24k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
630
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
Transcript
Docker 入門
疑問 そもそも Docker って何? コンテナ?
コンテナとは それぞれ隔離されたアプリケーション 実行環境
アーキテクチャ Linux Kernelの機能で、それぞれの環境を隔離。 chroot (ファイルシステムのルート切り替え) cgroup (CPU、メモリ、IOなどの物理的なリソース 制限) namespace (プロセス空間など、OSが扱うリソー
スの隔離) https://itnext.io/chroot-cgroups-and-namespaces- an-overview-37124d995e3d
ハイパーバイザ型仮想化
コンテナ型仮想化
対比 比 較 対 象 ハイパーバイザ コンテナ OS 自由に選択できる 基本的にホストOS
と同一 *1 効 率 VMそれぞれでOSを起動 するので、リソース効率 が悪い OSを共有するの で、オーバーヘッド が少ない *1 Kernelには後方互換性があるので、Ubuntu上で CentOSコンテナを起動するといったことも可
Docker app Docker Toolbox (Windows, Mac + Oracle VirtualBox) Docker
for Windows (Windows 10 Pro + Hyper-V) Docker for Mac (Mac El Capitan or Newer + Hypervisor)
Docker for Windows OS Native(Hyper-V)の機能を使うため、Docker Toolboxと比べて高速とのこと LinuxコンテナはHyper-V上に構築された MobyLinuxVMで実行される Windowsコンテナの実行も可能だが、切り替えが必 要でLinuxコンテナと並列で実行することはできない
※Hyper-VとVirtualBox VMは同時に使うことができ ないので注意 (Windows 10 Pro 1803 + VirtualBox 5.1.36で確認)
MobyLinuxVMについて Mobyフレームワークによって、以下のコンポーネン トで構築されたVM LinuxKit Linuxサブシステム containerd コンテナランタイム 元々Dockerエンジ ンのコアだったが独立 https://www.publickey1.jp/blog/17/dockermoby_pro
jectdockercon_2017.html
Moby コンポーネントを組み合わせて、コンテナシステムの 構築を行うフレームワーク LinuxKitを他のLinuxDistroに差し替えたり、コンテ ナランタイムを別ものに置き換えたりすることが可能 通常のDocker利用者は意識する必要はない
LinuxKit DockerはLinux Kernelの機能を使用してコンテナを 実現しているため、 他OSでは動作させることができない そのため、Linux Kernelのコンテナ機能のみに絞って LinuxKitというサブシステムが構築された https://www.mirantis.com/blog/ok-i-give-up-is- docker-now-moby-and-what-is-linuxkit/
Docker Toolbox Oracle VirtualBoxなどのアプリケーション上でLinux VMを起動、その上でコンテナを実行する Hyper-Vが使用できない場合はこれを使うことになる Windowsコンテナは利用できない
実践
Powershellでコマンド実行 # "hello-world"イメージをダウンロード docker pull hello-world # hello-worldイメージからコンテナを生成、起動 docker run
hello-world # nginxイメージからwebserverという名前でコンテナを生成 # 80ポートで待機 (pullを除くと3秒前後で起動した) docker run --detach --publish 80:80 --name webserver nginx # webserverコンテナを停止 docker stop webserver # webserverコンテナを再開 docker start webserver
イメージとは 何のコマンドを実行するのか、どういった設定をする かなどのメタデータの集合体 https://www.slideshare.net/zembutsu/docker- images-containers-and-lifecycle
Docker le イメージ設定、コンテナ起動時の挙動を定義
Docker le # Dockerhubのpython 3.6.6 slimイメージを元に作成 FROM python:3.6.6-slim # ワーキングディレクトリを/appにセット
WORKDIR /app # /appにカレントディレクトリのファイル等をコピー ADD . /app # pip インストールを実行 RUN pip install -r requirements.txt # 80番ポートを開放 EXPOSE 80 # 環境変数をセット ENV Name Foo # コンテナ起動時にapp.pyを実行 CMD ["python", "app.py"]
Docker le |- app.py | |- Docker le | |-
requirements.txt
Docker le # myfirstappという名前でイメージをビルド docker build -t myfirstapp . #
ホストの4000番ポートとコンテナの80番ポートをマップして起動 docker run --publish 4000:80 myfirstapp # 確認 curl http://localhost:4000
イメージの拡張ができるよう に
複数のコンテナを管理したい 場合
docker-compose.yml version: "3" services: web: image: myfirstapp deploy: replicas: 5
resources: limits: cpus: "0.1" memory: 50M restart_policy: condition: on-failure ports: - "4000:80" networks: - webnet networks:
docker-compose.yml # クラスタ環境を構築 docker swarm init # クラスタ環境に記載した通りのサービスをデプロイ docker stack
deploy -c docker-compose.yml # ラウンドロビン方式で各インスタンスにリクエストが割り振られる curl http://localhost:4000
所感 マルチサーバ、マルチコンテナ環境の構築やDBデー タの永続化については継続して調査が必要 体感だがハイパーバイザ方式に比べて起動が高速なの で導入してみたいが、Docker Toolboxだとどれだけ 効果が得られるか? DBはともかく、データの保持が必要ないWeb、App サーバであればそのまま使えそう オーバーヘッドが少ないとはいえ、ベアメタルサーバ
と比べてどれだけ本番環境で使えるか
https://bitbucket.org/rshimada/dock er-sample/