LoginSignup
18
19

More than 5 years have passed since last update.

nsinit が上手く行かなくて困っていたら nsenter があまりにもあっさりだった件

Last updated at Posted at 2014-06-26

mog project: Docker: How to Run 'nsinit' in the boot2docker VMyungsang/boot2docker で試してみたところ、nsinit でエラーが出てどうしても上手く行かなかった。
failed to nsenter: drop capabilities operation not permitted

本家の boot2docker-cli + boot2docker.iso では問題無く自分の環境でも上手く行くので、何が違うのか気になって調べてみることに。

(ここまで昨日)

(ここから今日)

  1. NFS を入れて独自に boot2docker.iso をビルドしているので、一旦、本家と同じ状態で boot2docker.iso をビルドしてみた。=> エラーの表示が微妙に違うもののやはりエラーになって上手く行かず。
    failed to exec: bridge is not specified

  2. 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:~$ 

gogcc 等のでかいオブジェクトをダウンロード/インストールする必要も、ディレクトリへの移動も必要無くて、簡単にアタッチ出来るー

ちなみに、

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/boot2dockernsenter 標準搭載しようかな。

18
19
7

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
19