CloudNative Days Spring 2021 ONLINE キーノートでの発表資料です。
https://event.cloudnativedays.jp/cndo2021/talks/1071
本セッションでは、DockerとKubernetesのもつ基本的な機能の概要を、コンテナの仕組みをふまえつつイラストを用いて紹介していきます。一般にあまり焦点をあてて取り上げられることは多くありませんが、コンテナの作成や管理を担う低レベルなソフトウェア「コンテナランタイム」も本セッションの中心的なトピックのひとつです。
本セッションは、拙著「イラストで分かるDockerとKubernetes」(技術評論社)の内容を参考にしています。
https://www.amazon.co.jp/dp/4297118378
14. Docker
14
“Docker allows you to package an application
with all of its dependencies into a standardized
unit for software development.”
www.docker.com
全ての依存関係をパッケージ化して、コンテナとして動かす
15. Dockerはサーバ・クライアント型モデル
15
OS ( Linux )
物理/仮想サーバ
Docker エンジン
( dockerd デーモン )
Linux kernel
コンテナ コンテナ コンテナ
リモート
API
docker
クライアント TCP あるいは
Unix ソケットドメイン
containerd
Runtime: runC (OCI規格準拠)
・docker コマンド
Linux, Mac OS X, Windows
・Kitematic (GUI)
Mac OS X, Windows
・Docker Compose
・Docker Swarm
19. docker クライアント docker エンジン
docker container run hello-world
OSに対してdocker プログラムの
実行を伝える
Docker に対してコンテナに読み込む
イメージの情報を伝える
Docker コンテナを作成・実行
するためのサブコマンド
$ docker container run hello-world
run
19
20. docker クライアント docker エンジン
$ docker container run hello-world
run
Docker Hub
pull
レジストリ
latest
イメージ
タグ
hello-world レポジトリ
latest
イメージ
タグ
latest
コンテナ化した
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.
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
Share images, automate workflows, and more with a free Docker Hub
account:
https://hub.docker.com
For more examples and ideas, visit:
https://docs.docker.com/userguide/
20
21. $ docker container run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
03f4658f8b78: Pull complete
a3ed95caeb02: Pull complete
Digest: sha256:8be990ef2aeb16dbcb9271ddfe2610fa6658d13f6dfb8bc72074cc1ca36966a7
Status: Downloaded newer image for hello-world:latest
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.
(省略)
Share images, automate workflows, and more with a free Docker Hub account:
https://hub.docker.com
For more examples and ideas, visit:
https://docs.docker.com/userguide/
ローカルにhello-worldイメージがない
公式イメージlibraryにある”hello-world”を取得
最新の”hello-world:latest”イメージを取得完了
hello-worldイメージを使ったコンテナの実行(run)を命令
21
42. docker container run
FROM alpine:latest
ENTRYPOINT ["ping","-c","3"]
CMD ["8.8.8.8"]
42
$ docker run -it myping:1.1
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=120 time=7.684 ms
64 bytes from 8.8.8.8: seq=1 ttl=120 time=1.153 ms
64 bytes from 8.8.8.8: seq=2 ttl=120 time=0.994 ms
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.994/3.277/7.684 ms
$ docker run -it myping:1.1 8.8.4.4
PING 8.8.4.4 (8.8.4.4): 56 data bytes
64 bytes from 8.8.4.4: seq=0 ttl=120 time=1.277 ms
64 bytes from 8.8.4.4: seq=1 ttl=120 time=1.252 ms
64 bytes from 8.8.4.4: seq=2 ttl=120 time=1.270 ms
--- 8.8.4.4 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 1.252/1.266/1.277 ms
Dockerfile
43. docker network
$ docker network create --subnet 192.168.0.1/24 mynet
44dd2cdd6120c5265ecacfece5bd66077de1e6ab67f453601b8058eb0f65757f
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
df54d986479d bridge bridge local
11dc9b54f1cc host host local
44dd2cdd6120 mynet bridge local
a786e4ae4841 none null local
43
44. $ docker run -it --net=mynet alpine
/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state
UNKNOWN qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
53: eth0@if54: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN>
mtu 1500 qdisc noqueue state UP
link/ether 02:42:c0:a8:00:02 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.2/24 brd 192.168.0.255 scope global eth0
valid_lft forever preferred_lft forever
44
45. Port mapping
• 「docker run -d -P nginx」は自動的にマッピング
• 「docker run -d -p 8080:80 nginx」は手動
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d11fc51679e2 nginx "nginx -g 'daemon of…" 18 seconds ago Up 16 seconds 0.0.0.0:32773->80/tcp focused_heisenberg
33ce5561ec1a nginx "nginx -g 'daemon of…" 19 seconds ago Up 17 seconds 0.0.0.0:32772->80/tcp gallant_ramanujan
a00d140e2500 nginx "nginx -g 'daemon of…" 19 seconds ago Up 18 seconds 0.0.0.0:32771->80/tcp adoring_euclid
5e0f1c10b6f7 nginx "nginx -g 'daemon of…" 20 seconds ago Up 19 seconds 0.0.0.0:32770->80/tcp flamboyant_meitner
cde6f341cacf nginx "nginx -g 'daemon of…" 26 seconds ago Up 25 seconds 0.0.0.0:32769->80/tcp cranky_rosalind
45
nmap -sT -O 127.0.0.1
ホスト側 コンテナ側
46. volume
$ docker run -it alpine
/ # date
Sat Aug 25 02:36:47 UTC 2018
$ docker run -it -v /etc/localtime:/etc/localtime alpine
/ # date
Sat Aug 25 11:37:38 JST 2018
46
ホスト側 コンテナ側