2020/11/20
今回できたこと
Docker Desktop for Macのインストールを行い、GUIに関して調べた。
Jetson Nanoにnvidiaランタイムが使えると思われるCUDA OpenGL Dockerイメージをpullした。
今後の作業
Docker Desktop for Windowsに関しても調査する。
Docker Desktop for Macとminikubeで入ったDockerとの関連性を調べる。
Jetson Nanoで、実際にnvidiaランタイムを使ったデモを行う。
お約束
参考文献
以下の文献を購入した。
コンテナ型仮想化概論(内容見本PDF): コンテナ技術だけの解説書で、Dockerを含むFreeBSD jailやSolarisゾーンなどの各種コンテナに関しても記述されている。 Docker Desktop for Macの初起動時チュートリアル
Docker Desktop for Macには、以下のような特徴がある。
多くのことがGUIから操作可能。
VirtualBox の代わりに HyperKit を使う(Hypervisor.framework 上で構築)。
Dockerコンテナに対するトラフィックには経路が無いため、ホスト側から直接Dockerコンテナ内にはアクセスできない。
仮想マシンは1つだけ使う。
Docker Desktop for Macには、以下のようなものが含まれている。
Dockerイメージの実行状況やWebブラウザベースコンソール実行などを行える専用のGUIアプリケーション
他には、以下のようなものが含まれている。
Docker Engine
Docker CLI クライアント
Docker Compose
Notary
Kubernetes: デフォルトでは無効に設定されている。
Credential Helper
インストールした最新のバージョンは、以下の通り。
https://gyazo.com/1425c7b78372108fcde5dd5611cec473
初起動時のチュートリアルを実行する。
このチュートリアルは4ステップと簡潔だが、docker hubへのイメージのpushを含む基本的な作業が含まれている。
はじめに、チュートリアル用のイメージをcloneする。
code:shell
Unable to find image 'alpine/git:latest' locally
latest: Pulling from alpine/git
df20fa9351a1: Pull complete
c04c7f41a94d: Pull complete
cfb833d2ca17: Pull complete
Digest: sha256:7b94cd6038bf3f5ddd7b1d99b9591f243e6484417bc5fb8fa7fdbc076e904794
Status: Downloaded newer image for alpine/git:latest
% docker cp repo:/git/getting-started/ .
% docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine/git latest a8b6c5c0eb62 4 weeks ago 28.4MB
次に、実習用のDockerfileを用いて、コンテナイメージのbuildを行う。
code:Dockerfile
# Install the base requirements for the app.
# This stage is to support development.
FROM python:alpine AS base
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
# Run tests to validate app
FROM node:12-alpine AS app-base
WORKDIR /app
COPY app/package.json app/yarn.lock ./
RUN yarn install
COPY app/spec ./spec
COPY app/src ./src
RUN yarn test
# Clear out the node_modules and create the zip
FROM app-base AS app-zip-creator
RUN rm -rf node_modules && \
apk add zip && \
zip -r /app.zip /app
# Dev-ready container - actual files will be mounted in
FROM base AS dev
# Do the actual build of the mkdocs site
FROM base AS build
COPY . .
RUN mkdocs build
# Extract the static content from the build
# and use a nginx image to serve the content
FROM nginx:alpine
COPY --from=app-zip-creator /app.zip /usr/share/nginx/html/assets/app.zip
COPY --from=build /app/site /usr/share/nginx/html
code:shell
% cd getting-started
% docker build -t docker101tutorial .
(snip)
作成したコンテナを実行する。
code:shell
% docker run -d -p 80:80 --name docker-tutorial docker101tutorial
dd4fa0f8866f349d2d7b9080d6d080f7f426e2c194f9ede6093d3bb451924893
% docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dd4fa0f8866f docker101tutorial "/docker-entrypoint.…" 11 seconds ago Up 10 seconds 0.0.0.0:80->80/tcp docker-tutorial
途中で、docker hubへのサインインが求められる。
code:shell
% docker tag docker101tutorial 610g/docker101tutorial
% docker push 610g/docker101tutorial
36874f4ebb05: Pushed
d511e9c59fe6: Pushed
2367050c34dd: Mounted from library/nginx
2c8583333eb3: Mounted from library/nginx
e2a648dc6400: Mounted from library/nginx
93e19e6dd56b: Mounted from library/nginx
ace0eda3e3be: Mounted from library/nginx
latest: digest: sha256:cb56ba63038492e264e93c1471d9b853ad20f92064169d5fcac0386c9c8290fc size: 1782
code:shell
% docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dd4fa0f8866f docker101tutorial "/docker-entrypoint.…" 13 minutes ago Up 13 minutes 0.0.0.0:80->80/tcp docker-tutorial
% docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
610g/docker101tutorial latest f628e20d3825 27 minutes ago 27.2MB
docker101tutorial latest f628e20d3825 27 minutes ago 27.2MB
alpine/git latest a8b6c5c0eb62 4 weeks ago 28.4MB
共有したコンテナイメージは、docker hubのページから、以下のように確認ができる。
https://gyazo.com/b188bdf9828d9636f30fb9f672f2286e
コマンドラインから、現在動いているコンテナの情報に関して調べた。
IPアドレス: 172.17.0.2/16
ルーティング: default 172.17.0.1
ホスト名: ba8aa318b35b(container IDと同じ)
起動しているサービス: httpd(nginx), TCP/IP:80
code:shell
% docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ba8aa318b35b docker101tutorial "/docker-entrypoint.…" 3 hours ago Up 3 hours 0.0.0.0:80->80/tcp docker-tutorial
% docker exec -it ba8aa318b35b /bin/sh
# hostname
ba8aa318b35b
# ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:02
inet addr:172.17.0.2 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1296 (1.2 KiB) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
# ps agxuww
PID USER TIME COMMAND
1 root 0:00 nginx: master process nginx -g daemon off;
29 nginx 0:00 nginx: worker process
30 nginx 0:00 nginx: worker process
49 root 0:00 /bin/sh
55 root 0:00 ps agxuwwte
# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:http 0.0.0.0:* LISTEN
tcp 0 0 :::http :::* LISTEN
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 3 STREAM CONNECTED 23349
unix 3 STREAM CONNECTED 23351
unix 3 STREAM CONNECTED 23350
unix 3 STREAM CONNECTED 23348
# netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 172.17.0.1 0.0.0.0 UG 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
この実習用のDockerコンテナイメージは、起動時に以下のようなシェルスクリプトを実行する。
nginx httpdを/docker-entrypoint.d/*の設定に従って動かす。
code:/docker-entrypoint.sh
# vim:sw=4:ts=4:et
set -e
exec 3>&1
else
exec 3>/dev/null
fi
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
echo >&3 "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
find "/docker-entrypoint.d/" -follow -type f -print | sort -n | while read -r f; do
case "$f" in
*.sh)
echo >&3 "$0: Launching $f";
"$f"
else
# warn on shell scripts without exec bit
echo >&3 "$0: Ignoring $f, not executable";
fi
;;
*) echo >&3 "$0: Ignoring $f";;
esac
done
echo >&3 "$0: Configuration complete; ready for start up"
else
echo >&3 "$0: No files found in /docker-entrypoint.d/, skipping configuration"
fi
fi
exec "$@"
nginxの設定ファイルは以下の通り。
code:shell
# ls /docker-entrypoint.d/
10-listen-on-ipv6-by-default.sh 20-envsubst-on-templates.sh
Docker Desktop for Macの設定項目
Docker Desktopの設定項目を確認する。
以下の値は、全てデフォルトの状態である。
設定項目は、以下のように別れている。
General
Resources
ADVANCED
FILE SHAREING
PROXIES
NETWORK
Docker Engine
Experimental Features
Kubernetes
https://gyazo.com/aa36e4b1aee9002b389b9fb90d8f807a
以下、各設定に関して、確認する。
Generalには、以下のような項目が存在する。
Start Docker Desktop when you log in: ユーザのログイン時にDockerを起動するかどうか。
Automatically check for updates: Docker Desktopの更新を自動的に確認するかどうか。
Include VM in Time Machine backups: VMをTime Machineでバックアップするかどうか。
Securely store Docker logins in macOS keychain: ログイン情報をmacOSのキーチェーンに保存するかどうか。
Send usage statistics: 統計情報を運用者に送るかどうか。
https://gyazo.com/fbfee9d6fd7c54ddd5593e1a1bba3821
Resourcesには、サブメニューが4つ存在する。
Advanced: CPUやメモリなどのリソースの設定を行う。
https://gyazo.com/b5bc645d221440f23321078e949976c0
File Sharing: コンテナ内部とホスト内部で共有することのできるディレクトリを指定する。
https://gyazo.com/a23f395ef344fd0a47ae81b419fe4311
Proxies: Proxyが必要な場合に設定する。
https://gyazo.com/f30f71720a6411e534efe034963767e4
Network: Dockerコンテナが接続されている172.17.0.2/16の上位のネットワーク(マスターノードの上流側?)の設定。
https://gyazo.com/6927ddc70b25d95b11f1c08d8b82c903
Docker Engine: Docker Engineのバージョン情報など。Docker daemonの設定は、JSON形式の設定ファイルで行う。
https://gyazo.com/6462d8dde6f8485ea1b775232c806b87
Experimental Features: 実験的な機能の有効化/無効化。
Enable CLI experimental features: CLIで実験的な機能を使うかどうか。
Enable cloud experience: Compose CLI(cloud experience?)を有効にするかどうか
Use gRPC FUSE for file sharing: Dockerホストとコンテナでファイルを共有するためにgRPC(?)を使うかどうか。
https://gyazo.com/040f6388ca6e6ea9c3903727cbc838b7
Kubernetes: K8sに関する設定。
Enable Kubernetes: Docker Desktop起動時に、シングルノードクラスタのK8sを有効化する。
Deploy Docker Stacks to Kubernetes by default: K8sのデフォルトオーケストラとしてdocker stackを使う。
Show system container (advanced) : Dockerコマンド利用時に、K8s内部のコンテナを表示する。
Reset Kubernetes Cluster: K8sで使っている全てのリソースを削除する。
https://gyazo.com/7ca05b3d197628cf318e41a83b807309
Docker Desptopを使う
Docker Desktopからは、コンテナに対して、logやCLIの起動、再起動や停止、実行などができるようになっている。
操作は右上のアイコンを使って行う。
https://gyazo.com/90457f833db9247b9345ab91ec53d66a
それぞれ左から右に向かって、以下のような機能を呼び出す。
CLI: ターミナルを使って、CLIインタフェースでの操作を行う(exec -it ... /bin/sh相当)。
docker exec -it ba8aa318b35b48733986d07197c7113ba2f13e4e44406eb8c239b131ee59daa1 /bin/sh; exit
STOP: コンテナを停止する。
コンテナ停止時にはSTARTに変わる。
RESTART: コンテナを再起動する。
DELETE: コンテナを削除する。
下の図は、ログを表示している状態である。
CMDなどで起動したコマンドの標準出力が表示されていく。
https://gyazo.com/44ac50f0bd9acb14c9c30018899484d5
下の図は、Inspectを表示している状態である。
環境変数や、コンテナのポートから外部サービスとして公開されるポートの割り当て状況が確認できる。
https://gyazo.com/083b0a6c5b9232680b991b9c035eb4fa
下の図は、Statsを表示している状態で、以下のような統計情報が表示されている。
CPU USAGE: CPUの利用状況
MEMORY USAGE: メモリの利用状況
DISK READ/WRITE: ディスクへの読み込み量と書き込み量
NETWORK I/O: ネットワークのI/Oの状況
https://gyazo.com/acd0207e54bd6635f9003fed92bac936
更に、イメージの管理を行うUIもある。
ここでは、イメージに対して、以下のようなことが実行できる。
RUN: 実行
Inspect: イメージに関する詳細情報を表示する。
Remove: イメージの消去。
Push: イメージを取得する。
Push to Hub: docker hubにイメージをpushする。
他にも、リモートのリポジトリイメージを操作することもできるが、詳細は省略する。
https://gyazo.com/7604c24e7341a5824f99bdb181a95747
Inspectすると、以下のような情報が得られる。
これは、Dockerfileを用いてbuildした時の情報のようだ。
https://gyazo.com/da99233cf7c59ff510ee48bcd48764f8
JetsonNano nvidiaランタイム実験
nvidiaランタイムが使えるコンテナとして、CUDA GLが使えそうなので、イメージの取得を行なった。 code:shell
$ sudo docker pull nvcr.io/nvidia/cudagl:11.0-devel-centos8
11.0-devel-centos8: Pulling from nvidia/cudagl
3c72a8ed6814: Pull complete
3dd6c66eceb5: Pull complete
eb5bfbb00010: Pull complete
431f78446c16: Pull complete
5db4dc47c988: Pull complete
7e3ff5265d99: Pull complete
461f471d5404: Pull complete
bfbdda3973d4: Pull complete
ce6507f52b0b: Pull complete
d58ba326dc06: Pull complete
f15bf2181e35: Pull complete
944efbd464c0: Pull complete
a748bad7fcb1: Pull complete
1742b6b77c8f: Pull complete
7c5b76e57aff: Pull complete
9649f49580c9: Pull complete
098578fc4b47: Pull complete
54fc280e6c0b: Pull complete
92a06b1b8194: Pull complete
ccbb1ee718fe: Pull complete
c618d12b5eac: Pull complete
Digest: sha256:f751f1714b786b2a65ef875f47ab8a137542d150f59874a8c3f258f297e565f0
Status: Downloaded newer image for nvcr.io/nvidia/cudagl:11.0-devel-centos8
nvcr.io/nvidia/cudagl:11.0-devel-centos8
$ sudo docker images|grep nvidia
nvcr.io/nvidia/cudagl 11.0-devel-centos8 acb6e712587f 2 days ago 4.07GB
nvcr.io/nvidia/l4t-base r32.2.1 593e936de911 15 months ago 1.06GB
次回以降、このイメージの調査を行う。