2020/11/06
今回できたこと
Dockerに関する調査。
Docker 公式のhttpdコンテナイメージを動かす。
Jetson Nano関連:
Dockerでのnvidiaランタイムの利用方法調査。
l4t-base Dockerイメージを動かす。
K3s環境構築。
未解決
Jetson Nanoのデフォルトランタイムをnvidiaに変更する。
お約束
Docker に関する調査
参考文献
JetsonNano の Docker でnvidiaランタイムを利用する
サポートしているランタイムを調べる。
code:shell
$ sudo docker info|grep Runtime
Runtimes: nvidia runc
Default Runtime: runc
デフォルトでは、runcランタイムが利用されている。
nvidiaランタイムでは、GPUが利用可能。
nvidiaランタイムを利用するためには…
1. Dockerコマンドラインオプションで--runtime nvidiaを指定する。
2. 失敗中: /etc/docker/daemon.jsonに"default-runtime": "nvidia",を追加する。
code:/etc/docker/daemon.json.diff
$ diff -ruN //etc/docker/daemon.json{.20201106,}
--- //etc/docker/daemon.json.20201106 2020-11-06 10:02:22.481077326 +0900
+++ //etc/docker/daemon.json 2020-11-06 10:04:11.018486792 +0900
@@ -1,5 +1,6 @@
{
"runtimes": {
+ "default-runtime": "nvidia",
"nvidia": {
"path": "nvidia-container-runtime",
"runtimeArgs": []
Dockerの再起動を行う; なぜか現状では動かない
code:shell
$ sudo systemctl restart docker
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xe" for details.
JetsonNano Docker で l4t-baseを動かす
code:shell
$ sudo docker run --runtime nvidia -it nvcr.io/nvidia/l4t-base:r32.2.1
Unable to find image 'nvcr.io/nvidia/l4t-base:r32.2.1' locally
r32.2.1: Pulling from nvidia/l4t-base
(snip)
Digest: sha256:d76b1a4521f06810b065c550c4c451f4b66f4cbf40a0ecfdd418eb0c777836db
Status: Downloaded newer image for nvcr.io/nvidia/l4t-base:r32.2.1
root@943d0563f145:/#
Dockerの動作状況を確認する。
code:shell
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e18ccf8b7dfa nvcr.io/nvidia/l4t-base:r32.2.1 "/bin/bash" About a minute ago Up About a minute busy_wilson
code:shell
root@e18ccf8b7dfa:/# ps agxu
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.2 0.0 3784 2984 pts/0 Ss 01:18 0:00 /bin/bash
root 15 0.0 0.0 5284 2296 pts/0 R+ 01:18 0:00 ps agxu
Networkの構成を確認する。
code:shell
$ ifconfig docker0
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:5bff:fea3:80f6 prefixlen 64 scopeid 0x20<link>
ether 02:42:5b:a3:80:f6 txqueuelen 0 (イーサネット)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 30 bytes 3570 (3.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
code:shell
root@e18ccf8b7dfa:/# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.2 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:ac:11:00:02 txqueuelen 0 (Ethernet)
RX packets 22 bytes 2638 (2.6 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
httpd(nginx)を動かす。
注意: Dockerコンテナ内でapt upgradeやapt installしても、Dockerコンテナを終了するとその効果は無くなる。
code:shell
# nginxサーバのインストール
root@e18ccf8b7dfa:/# apt update
(snip)
root@2c72baa838fb:/# apt install nginx-full
(snip)
code:shell
# nginxサーバの起動
root@2c72baa838fb:/# /usr/sbin/nginx
root@2c72baa838fb:/# ps agxu
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 3896 2992 pts/0 Ss 01:46 0:00 /bin/bash
root 10124 0.0 0.0 48508 2324 ? Ss 01:59 0:00 nginx: master p
www-data 10125 0.0 0.1 49184 6220 ? S 01:59 0:00 nginx: worker p
www-data 10126 0.0 0.1 49184 6220 ? S 01:59 0:00 nginx: worker p
www-data 10127 0.0 0.1 49184 6116 ? S 01:59 0:00 nginx: worker p
www-data 10128 0.0 0.1 49184 6108 ? S 01:59 0:00 nginx: worker p
root 10129 0.0 0.0 5288 2356 pts/0 R+ 01:59 0:00 ps agxu
code:shell
# Dockerを動かしているホストからhttpd(nginx)が動作していることを確認
$ telnet 172.17.0.2 80
Trying 172.17.0.2...
Connected to 172.17.0.2.
Escape character is '^]'.
GET /index.html
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.14.0 (Ubuntu)</center>
</body>
</html>
Connection closed by foreign host.
Docker 公式のhttpdコンテナイメージを動かす
httpdを動かす。
code:shell
$ sudo docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
4e6164a63b7b: Pull complete
87b9a2083d46: Pull complete
d082fb52cd75: Pull complete
96a60244b989: Pull complete
2026bc748201: Pull complete
Digest: sha256:b82fb56847fcbcca9f8f162a3232acb4a302af96b1b2af1c4c3ac45ef0c9b968
Status: Downloaded newer image for httpd:latest
docker.io/library/httpd:latest
$ sudo docker run --runtime nvidia -it httpd
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
Dockerホスト側からhttpdに接続する。
code:shell
$ telnet 172.17.0.2 80
Trying 172.17.0.2...
Connected to 172.17.0.2.
Escape character is '^]'.
GET /index.html
<html><body><h1>It works!</h1></body></html>
Connection closed by foreign host.
httpd Docker側では以下のようなログが表示される。
172.17.0.1 - - [06/Nov/2020:03:03:40 +0000] "GET /index.html" 200 45
httpd Dockerコンテナの停止
code:shell
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1742cbdd956b httpd "httpd-foreground" 12 minutes ago Up 12 minutes 80/tcp bold_varahamihira
# コンテナIDを使って、コンテナを停止する。
$ sudo docker stop 1742cbdd956b
1742cbdd956b
# 動いているコンテナを全て一度に停止する。
$ sudo docker ps|tail +2|awk '{print "docker stop "$1}'|sudo sh
757f164108ca
fcd63530c081
0a0824fa5ae8
ba5f89b65a05
f309a4ec085c
5b1044b15f90
c8118dbabdbe
c27a8350a673
0200ba4cce0d
98fce8cc8e6a
8ea6c8e79862
httpd Dockerコンテナで、自分のコンテンツを表示する。
ホスト側の任意のディレクトリをコンテナ側の任意のディレクトリとしてマウントすることができる(-vオプション)。
コンテンツの作成
code:shell
$ mkdir /tmp/mypage
$ echo "My Page." > /tmp/mypage/index.html
コンテナの起動
-vオプションを使って、ホスト側の/tmp/mypageをコンテナ内では/usr/local/apache2/htdocs/としてアクセスできるようにする。
code:shell
$ sudo docker run -v "/tmp/mypage/:/usr/local/apache2/htdocs/" httpd
ホスト側からのWebページの参照
code:shell
$ telnet 172.17.0.2 80
Trying 172.17.0.2...
Connected to 172.17.0.2.
Escape character is '^]'.
GET /index.html
My Page.
Connection closed by foreign host.
JetsonNano に K3s 環境を構築する
code:shell
INFO Finding release for channel stable INFO Using v1.18.9+k3s1 as release INFO Verifying binary download INFO Installing k3s to /usr/local/bin/k3s INFO Creating /usr/local/bin/kubectl symlink to k3s INFO Creating /usr/local/bin/crictl symlink to k3s INFO Skipping /usr/local/bin/ctr symlink to k3s, command exists in PATH at /usr/bin/ctr INFO Creating killall script /usr/local/bin/k3s-killall.sh INFO Creating uninstall script /usr/local/bin/k3s-uninstall.sh INFO env: Creating environment file /etc/systemd/system/k3s.service.env INFO systemd: Creating service file /etc/systemd/system/k3s.service INFO systemd: Enabling k3s unit Created symlink /etc/systemd/system/multi-user.target.wants/k3s.service → /etc/systemd/system/k3s.service.
INFO systemd: Starting k3s