Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Docker 入門
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
airhand
July 03, 2018
100
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
81
ansible入門
airhand
0
260
Featured
See All Featured
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Leo the Paperboy
mayatellez
8
2.2k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
410
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
250
Utilizing Notion as your number one productivity tool
mfonobong
4
570
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
270
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/