mog project: Docker: How to Run 'nsinit' in the boot2docker VM を yungsang/boot2docker で試してみたところ、nsinit でエラーが出てどうしても上手く行かなかった。
failed to nsenter: drop capabilities operation not permitted
本家の boot2docker-cli + boot2docker.iso では問題無く自分の環境でも上手く行くので、何が違うのか気になって調べてみることに。
(ここまで昨日)
(ここから今日)
-
NFS を入れて独自に
boot2docker.isoをビルドしているので、一旦、本家と同じ状態でboot2docker.isoをビルドしてみた。=> エラーの表示が微妙に違うもののやはりエラーになって上手く行かず。
failed to exec: bridge is not specified -
boot2docker.isoビルド用のホストに boot2docker 自身を使っているので、まさかとは思ったが念の為、CoreOS でもビルドしてみる。=>Dockerfileからビルドする時点でエラーを吐いてboot2docker.isoをビルド出来ず。CoreOS はこういうのには向かないと。
Cannot mknod: Operation not permitted
その後、ubuntu や debian でやってみても全てダメ。
これはおかしいと、
Docker の nsinit を CoreOS で試してみた - Qiita をやってもダメ。
まさかと思って再度試したら boot2docker-cli + boot2docker.iso でもダメになって。。。
これは go get github.com/docker/libcontainer/nsinit で取ってくるソースの状態に左右されているな。
boot2docker.iso のビルドから何回もテストしたので、まる1日使ってしまった(´・ω・`)
ちなみに、
Attaching to a container with Docker 0.9 and libcontainer
にもあるもう一つの方法、nsenter を試してみたところ、nsinit よりも簡単にアタッチ出来ることを確認しました。
しかも、上記全てのケースで動作しました。
docker@boot2docker:~$ tce-load -wil util-linux
docker@boot2docker:~$ sudo nsenter --target $(docker inspect --format '{{.State.Pid}}' 7dab329c20b5) --mount --uts --ipc --net --pid
# ps
PID USER COMMAND
1 root nc -p 8080 -l -l -e echo hello world!
8 root -sh
13 root ps
# exit
docker@boot2docker:~$
go や gcc 等のでかいオブジェクトをダウンロード/インストールする必要も、ディレクトリへの移動も必要無くて、簡単にアタッチ出来るー
ちなみに、
CoreOS に nsinit が搭載される予定はあるか聞いてみた。(nsinit がイケると思っていた昨日の朝のこと)
Do you have a plan to bundle nsinit like toolbox in CoreOS? · Issue #696 · coreos/coreos-overlay
> > I just noticed that github.com/codegangsta/cli is not shipped inside of the
> > vendor directory. This is required by the nsinit tool
> > (docker/pkg/libcontainer/nsinit).
> The "nsinit" tool is not actually officially supported, and only
> exists for development purposes (which is why that dep isn't
> included). Hopefully soon, the ability of nsinit to enter an existing
> container with a new command will become a standard feature (it is
> in-progress).
>
> - Tianon
So nsenter is the way to go until upstream blesses nsinit as supported or provides alternate functionality that they do want to support.
とのこと。
今のところは nsenter の方が良さそうです。
次の版から yungsang/boot2docker に nsenter 標準搭載しようかな。