Docker Desktop 4.26.0がリリースされているのに気が付き、リリースノートを眺めていました。 Features in developmentの設定を管理者が一括管理できるようになったんだ(ただし、Docker Business版以降)、 Docker initでPHPサポートが追加されたのかとか、Builds ViewがGAになったのかとか確認したあと、
Extensionにアップデートを示すマークが表示されていたので見にいったところ、 「Docker Labs K8s Toolkit」というDocker Desktopのアドオンがリリースされたのに気が付きました。

これはDocker Lab製のアドオンで、名前の通りKubernetesのデバッグに使えるツールです。 Running状態なのに何か思ったように動いていないPodを確認したり、Podに入ってLinuxの色々なコマンドを使って状態を確認するのに便利そうです。
/usr/binや/usr/sbinコマンドのほとんどはbusyboxに関連付けられていました。
$ kubectl get po
NAME READY STATUS RESTARTS AGE
nginxapp-6586466998-jnszb 1/1 Running 0 29s
nginxapp-6586466998-ttzrf 1/1 Running 0 29s
$ kubectl shell nginxapp-6586466998-jnszb
# . ________ __
# # # == \______ \ ____ ____ | | __ ____ _______
# # # # # === | | \ / _ \ _/ ___\ | |/ /_/ __ \ \_ __ \
/""""""""""""\__/ === | ` \( <_> )\ \___ | < \ ___/ | | \/
{ / == /_______ / \____/ \___ >|__|_ \ \___ > |__|
\ __/ \/ \/ \/ \/
\___________/
This is an attach shell, i.e.:
- Any changes to the container filesystem are visible to the container directly.
- The /nix directory is invisible to the actual container.
Feature requests and feedback: https://github.com/docker/roadmap/issues/590
Bug reports: https://github.com/docker/roadmap/issues/523 Version: 0.0.46
root@nginxapp-6586466998-jnszb / [nginxapp]
root@nginxapp-6586466998-jnszb / [nginxapp]
docker > ls -la /usr/bin
total 2576
drwxr-xr-x 1 root root 4096 Dec 1 02:40 .
drwxr-xr-x 1 root root 4096 Nov 30 09:34 ..
lrwxrwxrwx 1 root root 12 Nov 30 09:34 '[' -> /bin/busybox
lrwxrwxrwx 1 root root 12 Nov 30 09:34 '[[' -> /bin/busybox
lrwxrwxrwx 1 root root 12 Nov 30 09:34 awk -> /bin/busybox
lrwxrwxrwx 1 root root 12 Nov 30 09:34 basename -> /bin/busybox
lrwxrwxrwx 1 root root 12 Nov 30 09:34 bc -> /bin/busybox
lrwxrwxrwx 1 root root 12 Nov 30 09:34 beep -> /bin/busybox
lrwxrwxrwx 1 root root 12 Nov 30 09:34 blkdiscard -> /bin/busybox
lrwxrwxrwx 1 root root 12 Nov 30 09:34 bunzip2 -> /bin/busybox
lrwxrwxrwx 1 root root 12 Nov 30 09:34 bzcat -> /bin/busybox
lrwxrwxrwx 1 root root 12 Nov 30 09:34 bzip2 -> /bin/busybox
-rwxr-xr-x 1 root root 67424 May 6 2023 c_rehash
...
root@nginxapp-6586466998-jnszb / [nginxapp]
docker > ls -la /usr/sbin/
total 2872
drwxr-xr-x 1 root root 4096 Dec 1 02:40 .
drwxr-xr-x 1 root root 4096 Nov 30 09:34 ..
lrwxrwxrwx 1 root root 12 Nov 30 09:34 add-shell -> /bin/busybox
lrwxrwxrwx 1 root root 12 Nov 30 09:34 addgroup -> /bin/busybox
lrwxrwxrwx 1 root root 12 Nov 30 09:34 adduser -> /bin/busybox
lrwxrwxrwx 1 root root 12 Nov 30 09:34 arping -> /bin/busybox
lrwxrwxrwx 1 root root 12 Nov 30 09:34 brctl -> /bin/busybox
...
-rwxr-xr-x 1 root root 1361904 Oct 24 16:48 nginx
-rwxr-xr-x 1 root root 1496152 Oct 24 16:48 nginx-debug
..
-rwxr-xr-x 1 root root 67256 May 6 2023 update-ca-certificates
このNGINXのイメージはAlpine linuxが使われていますが、kubectl describe podsで該当のPodを確認すると、
PodにさらにDocker Labs K8s Toolkitイメージが追加されていました。これがNGINXのイメージに機能を追加しているようです。
... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 34m default-scheduler Successfully assigned default/nginxapp-6586466998-jnszb to docker-desktop Normal Pulling 34m kubelet Pulling image "docker.io/library/nginx:alpine" Normal Pulled 33m kubelet Successfully pulled image "docker.io/library/nginx:alpine" in 6.8s (6.8s including waiting) Normal Created 33m kubelet Created container nginxapp Normal Started 33m kubelet Started container nginxapp Normal Pulling 30m kubelet Pulling image "docker/labs-debug-tools-service:0.0.46" Normal Pulled 30m kubelet Successfully pulled image "docker/labs-debug-tools-service:0.0.46" in 29.649s (29.649s including waiting) Normal Created 30m kubelet Created container k8s-toolkit-debugger-a99af-xd9l5 Normal Started 30m kubelet Started container k8s-toolkit-debugger-a99af-xd9l5
提供されているシェルはNixOSを使っているようで、足りないパッケージはinstallコマンドで追加、要らなくなったらuninstallコマンドで削除できるようです。
docker > install ping-iputils docker > uninstall ping-iputils
インストールして、もう一つのPodと疎通確認をしたりとかも簡単にできます。 もうデバッグ用のコンテナイメージを開発者が用意する必要はないですね。少なくともDocker Desktopでは。
docker > install ping-iputils Tip: You can install any package available at: https://search.nixos.org/packages. installing 'ping-iputils-20211215' this path will be fetched (0.00 MiB download, 0.00 MiB unpacked): /nix/store/b1x6zagy5y9a1h6wp6z532hcny7h8rwh-ping-iputils-20211215 copying path '/nix/store/b1x6zagy5y9a1h6wp6z532hcny7h8rwh-ping-iputils-20211215' from 'https://cache.nixos.org'... building '/nix/store/s0i0algxdjb486s2z75x3z4m32r59h55-user-environment.drv'... root@nginxapp-6586466998-jnszb /var/log/nginx [nginxapp] docker > ping 10.1.0.7 PING 10.1.0.7 (10.1.0.7) 56(84) bytes of data. 64 bytes from 10.1.0.7: icmp_seq=1 ttl=64 time=0.198 ms 64 bytes from 10.1.0.7: icmp_seq=2 ttl=64 time=0.219 ms ^C --- 10.1.0.7 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1021ms rtt min/avg/max/mdev = 0.198/0.208/0.219/0.010 ms root@nginxapp-6586466998-jnszb /var/log/nginx [nginxapp]
Docker Labs K8s ToolkitはDocker Desktop上のKubernetesで使うのが前提ではありますが、 Kubernetesで動かすアプリの開発の初期などでデバッグなどのときに役立ちそうです。
Docker Desktopの拡張機能もだいぶ充実してきましたね。
