Docker入門-基礎編
いまから始めるDocker管理 v1.01
JAWS-UG CLI専門支部#23 - ECS 入門
2015年7月6日(月)
@zembutsu
Technology Evangelist; Creationline, Inc.
Introduction to docker, basic management and operations
背景画像CREDIT:スフィア / PIXTA(ピクスタ)
2.
2
このスライドで得られる知識
Docker入門-基礎編 いまから始めるDocker
‣ Docker概要と環境構築
なぜDocker なのか? 速さと利便性。そして、Docker はコンテナではなくプラットフォーム。
‣ Dockerの基本操作コマンドの理解
コンテナのイメージ管理、起動、情報取得、ログ参照、Dockerfile、ボリューム操作
‣ 捕捉:Dockerとコンテナを取り巻く状況
DockerCon 2015 前後、Dockerのオーケストレーション Docker Machine, Swarm, Compose
This slide is an introduction of the basic concept and command of Docker. Because the main purpose uses Docker as a
tool. This is a Japanese document for community of the JAWS-UG CLI Branch held in Tokyo on July 6.
Are you interested in this English version? Please comment me or mention @zembutsu . Thank you.
物理マシン 物理マシン 物理マシン
OSOS OS
HyperVisor HyperVisor HyperVisor
VM VM VM VM VM VM
Guest
OS
Guest
OS
Guest
OS
Guest
OS
Guest
OS
Guest
OS
物理マシン 仮想マシン クラウド
OS OS OS
Docker
Engine
Docker
Engine
Docker
Engine
App App App App App App
App App App App
仮想化・クラウド Dockerのコンテナ管理
なぜコンテナ管理用のプラットフォームが必要なの??
Dockerは管理用のシステム。
これまでと比較してみます。
20.
物理マシン 物理マシン 物理マシン
OSOS OS
HyperVisor HyperVisor HyperVisor
VM VM VM VM VM VM
Guest
OS
Guest
OS
Guest
OS
Guest
OS
Guest
OS
Guest
OS
物理マシン 仮想マシン クラウド
OS OS OS
Docker
Engine
Docker
Engine
Docker
Engine
GUI
CLI
API
Docker Cluster 管理レイヤ
( ECS, Docker Swarm, rkt, Rancher …etc )
App App App App App App App App App App
まだクラスタ管理の部分は
機能として足りていません。
現状の大きな課題です。
仮想化・クラウド Dockerのコンテナ管理
21.
物理マシン 物理マシン 物理マシン
OSOS OS
HyperVisor HyperVisor HyperVisor
VM VM VM VM VM VM
Guest
OS
Guest
OS
Guest
OS
Guest
OS
Guest
OS
Guest
OS
App App App App
物理マシン 仮想マシン クラウド
OS OS OS
Docker
Engine
Docker
Engine
Docker
Engine
App App App App App App
GUI
CLI
API
Docker Cluster 管理レイヤ
( ECS, Docker Swarm, rkt, Rancher …etc )
オーケストレーション
サービス検出・クラスタ管理
仮想化・クラウド Dockerのコンテナ管理
オーケストレーション技術で
インフラ層をまとめて管理・
抽象化できるかも・・・?
Google Kubernetes
CoreOS× libcontainer
TheOpen Container Project (OCP)
runC
Orchestration
PROJECT ORCA
appcは独自に継続
Linux
Foundation
事務局として協力
Google Container
Engine
IBM Containers
on Bluemix
OS LayerCloud Providers
Amazon ECS
( EC2 Container
Service )
協力 協力
協力
割と整理されつつあります。
Dockerいつ使うの?
今でしょ!的な…
27Introduction to DockerBasic Course
‣ 方法1:インストール用の汎用スクリプトを使用
wget -qO- https://get.docker.com/ | sh
service docker start
※ Ubuntu や Debian などは、こちらで Docker 社が提供する最新安定版をダウンロード可能
※ RHEL/CentOS の場合は、後述の個別パッケージをセットアップ
‣ 方法2:各ディストリビューション向けパッケージ
‣ 方法3:boot2docker を使う
※ Windows と Mac OS X は、VirtualBox 上の仮想サーバを使用
Dockerのセットアップ方法
その時点の最新版が使えます。
ディストリビューションや
バージョンで、パッケージの
名前が異なる場合があります。
28.
28Introduction to DockerBasic Course
‣ Linux
Linux Kernel の機能を使うので、
インストールスクリプトかパッケージをセットアップすることで
すぐに使えます。
‣ Windows・Mac OS
boot2docker(VirtualBox)で Linux 環境を仮想マシン上に作り、
そこに Docker の動く環境をセットアップします。
クライアントは、PC上のコマンドライン(ターミナル)で動作します。
OSごとに違いが?
31Introduction to DockerBasic Course
‣ sudo docker version
‣ sudo docker run hello-world
動作確認
Hello from Docker.
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(Assuming it was not already locally available.)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
For more examples and ideas, visit:
http://docs.docker.com/userguide/
「hello-world」コンテナは
テストで使われるものです。
33Introduction to DockerBasic Course
‣ Mac OS X 環境について
boot2docker をセットアップする
コマンドラインのクライアントを通して、
VirtualBox 仮想マシン上の docker に接続
‣ セットアップ
Docker for OS Xのインストーラーを使う
• https://github.com/boot2docker/osx-installer/releases/latest
Mac OS X で Docker を使うには?
34.
34Introduction to DockerBasic Course
‣ Boot2Docker-1.7.0.pkg のダウンロード
https://github.com/boot2docker/osx-installer/releases/download/v1.7.0/Boot2Docker-1.7.0.pkg
‣ セットアップ
Boot2Docker-1.7.0.pkg を実行し、インストーラーの指示に従
Dockの「Boot2Docker Start」を実行
• docker run hello-world 等が実行可能に
• 仮想マシンへのログインは「boot2docker ssh」
• ターミナルからも docker コマンドが利用可能
Docker for Mac OS X セットアップ手順
35.
35Introduction to DockerBasic Course
‣ Windows 環境について
boot2docker をセットアップする
コマンドラインのクライアントを通して、
VirtualBox 仮想マシン上の docker に接続
‣ セットアップ
Docker for Windows のインストーラーを使う
• https://github.com/boot2docker/windows-installer/releases/latest
Windows で Docker を使うには?
36.
36Introduction to DockerBasic Course
‣ docker-install.exe のダウンロード
https://github.com/boot2docker/windows-installer/releases/download/v1.7.0/docker-install.exe
‣ セットアップ
docker-install.exe を実行し、インストーラーの指示に従って設定
デスクトップの「Boot2Docker Start」を実行
• docker run hello-world 等が実行可能に
• 仮想マシンへのログインは「boot2docker ssh」
Docker for Windows セットアップ手順
60Introduction to DockerBasic Course
Docker イメージのレイヤー?
kernel
ベース・イメージ
(CentOS)
ベース・イメージ
(Ubuntu)
変更内容 A
変更内容 B
変更内容 C
書き込み可能領域
書き込み可能領域
レイヤーとは、それぞれの層
にあたるコンテナイメージで
す。基本にディストリビュー
ション毎のイメージがあり、
変更が加えられたものが、
DockerHubで配布されていま
す。ここまで読み込み専用で、
変更を加えることはできませ
ん。
コンテナ起動時は、その上に、
書き込み可能な領域を作成し
ます。この変更内容は保存
(commit)しないと破棄される
ものです。
61.
61Introduction to DockerBasic Course
‣ 既存のイメージに対する変更をコミットする
開発段階で多く用いられると思います。
‣ Dockerfile から作成する
別のマシン環境で環境を再現するときに便利な方法です。
‣ tar 形式のファイルからイメージを読み込む
環境移行時や、バックアップしているイメージの再利用に活用します。
イメージを構築するには
目的により、この3つの方法
を使い分けています。方法は
違いますが、イメージ作成と
いう意味では、共通です。
62.
62Introduction to DockerBasic Course
‣ docker diff
‣ docker history
差分と履歴の確認
$ docker diff <コンテナID>
A /hello.txt
C /root
A /root/.bash_history
$ docker history $IMEGEID
IMAGE CREATED CREATED BY SIZE
COMMENT
1b07ddefe341 2 minutes ago bash 66 B
6d4946999d4f 3 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B
9fd3c8c9af32 3 weeks ago /bin/sh -c sed -i 's/^#¥s*¥(deb.*universe¥)$/ 1.895 kB
435050075b3f 3 weeks ago /bin/sh -c echo '#!/bin/sh' > /usr/sbin/polic 194.5 kB
428b411c28f0 3 weeks ago /bin/sh -c #(nop) ADD file:b3447f4503091bb6bb 188.1 MB
diff | history
差分・履歴表示
63.
63Introduction to DockerBasic Course
‣ docker commit コマンド
docker commit [オプション] [コンテナID] [レポジトリ名:タグ]
コミットして変更内容を確定
$ docker commit $CONTAINER ecsdocker/myapp:1.0
1b07ddefe341abdae8f497a4dea24b2fef46a2a32621a0998fb0e7e8c2fbf666
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ecsdocker/myapp 1.0 1b07ddefe341 17 seconds ago 188.3 M
71Introduction to DockerBasic Course
Dockerfileの例
FROM ubuntu:14.04
RUN apt-get install -y wget
CMD /usr/bin/wget
FROM nginx
ADD ./contents /usr/share/nginx/html
どれもシンプルです。