(ヽ´ω`) < 助けてほしいマン

わからないことを助けてほしいマンが書くブログ

(ヽ'ω`) < Dockerでサービスが落とせない

(ヽ'ω`) < Dockerを触りだした

最近はやりのDockerとやらにそろそろ乗っておこうと思って触りだしたのだが、なんか早速つまづいた。

ちなみに使用してるバージョンは以下の通り。2014/10/03時点でCentOS7の公式リポジトリに掲載されているバージョン。

[root@localhost ~]# docker version
Client version: 0.11.1-dev
Client API version: 1.12
Go version (client): go1.2
Git commit (client): 02d20af/0.11.1
Server version: 0.11.1-dev
Server API version: 1.12
Go version (server): go1.2
Git commit (server): 02d20af/0.11.1

(ヽ'ω`) < このバージョン情報が後に重要に…

(ヽ'ω`) < Operation not permitted... またかよ

具体的にどういう症状かというと、コンテナにapacheをインストールしてサービスとして起動するところまでは問題なくできたのだが、サービスを終了させようとしても正常に落ちてくれない。

## インストールとサービスの起動までは問題なし
[root@localhost ~]# docker run -i -t centos:centos6 /bin/bash
bash-4.1# yum -y install httpd ; yum clean all
Loaded plugins: fastestmirror
base                                                                                    | 3.7 kB     00:00
base/primary_db                                                                         | 4.4 MB     00:00
## ... httpdインストールログ省略
Complete!
Loaded plugins: fastestmirror
Cleaning repos: base extras libselinux updates
Cleaning up Everything
bash-4.1# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.23 for ServerName
                                                           [  OK  ]
## サービスの再起動時に、既に80ポートが使用中とエラーが出る
bash-4.1# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.23 for ServerName
(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
                                                           [FAILED]
## 調べてみると確かにapacheユーザのプロセスが残っている                                                           
## ちなみに親のrootのプロセスは問題なく落ちている
bash-4.1# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  11356  1576 ?        Ss   07:25   0:00 /bin/bash
apache      56  0.0  0.2 175780  2228 ?        S    07:26   0:00 /usr/sbin/httpd
apache      57  0.0  0.2 175780  2228 ?        S    07:26   0:00 /usr/sbin/httpd
apache      58  0.0  0.2 175780  2228 ?        S    07:26   0:00 /usr/sbin/httpd
apache      59  0.0  0.2 175780  2228 ?        S    07:26   0:00 /usr/sbin/httpd
apache      60  0.0  0.2 175780  2228 ?        S    07:26   0:00 /usr/sbin/httpd
apache      61  0.0  0.2 175780  2228 ?        S    07:26   0:00 /usr/sbin/httpd
apache      62  0.0  0.2 175780  2228 ?        S    07:26   0:00 /usr/sbin/httpd
apache      63  0.0  0.2 175780  2228 ?        S    07:26   0:00 /usr/sbin/httpd
root        91  0.0  0.1  13368  1052 ?        R+   07:26   0:00 ps aux

## killしようとしてもOperation not permittedとなる
bash-4.1# killall httpd
httpd(56): Operation not permitted
httpd(57): Operation not permitted
httpd(58): Operation not permitted
httpd(59): Operation not permitted
httpd(60): Operation not permitted
httpd(61): Operation not permitted
httpd(62): Operation not permitted
httpd(63): Operation not permitted
httpd: no process killed
bash-4.1#

(ヽ'ω`) < apacheだけじゃない

Apacheだけの問題なのかな?と思ったが、なんとなく「root以外のユーザプロセスが殺せないんじゃ…」と思ったので確認。

[root@localhost ~]# docker run -i -t centos:centos6 /bin/bash
## testというユーザを作成
bash-4.1# useradd test

## testでpingを実行、プロセスIDは29
bash-4.1# su - test
[test@99e7fe90266f ~]$ ping www.google.co.jp > /dev/null &
[1] 29
[test@99e7fe90266f ~]$ exit
logout

## rootがプロセス29を殺そうとすると…
bash-4.1# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  11356  1572 ?        Ss   08:07   0:00 /bin/bash
test        29  0.0  0.1  16052  1016 ?        S    08:08   0:00 ping www.google.co.jp
root        30  0.0  0.1  13372  1056 ?        R+   08:08   0:00 ps aux
bash-4.1# kill -SIGKILL 29

## (ヽ'ω`)
bash: kill: (29) - Operation not permitted

## testならOK
bash-4.1# su - test
[test@99e7fe90266f ~]$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  11356  1572 ?        Ss   08:07   0:00 /bin/bash
test        29  0.0  0.1  16052  1016 ?        S    08:08   0:00 ping www.google.co.jp
root        31  0.0  0.1  44508  1400 ?        S    08:10   0:00 su - test
test        32  0.0  0.1  14780  1740 ?        S    08:10   0:00 -bash
test        49  0.0  0.1  16660  1160 ?        R+   08:10   0:00 ps aux
[test@99e7fe90266f ~]$ kill -SIGKILL 29
[test@99e7fe90266f ~]$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  11356  1572 ?        Ss   08:07   0:00 /bin/bash
root        31  0.0  0.1  44508  1400 ?        S    08:10   0:00 su - test
test        32  0.0  0.1  14780  1852 ?        S    08:10   0:00 -bash
test        50  0.0  0.1  16660  1160 ?        R+   08:10   0:00 ps aux
[test@99e7fe90266f ~]$

(ヽ'ω`) < これがDockerってやつか…奥が深いな…

と思って、色々調べて--privileged=trueオプションをつけると問題がなかったりするので、Dockerのセキュリティ周りの仕組みを色々調べてたら。

(ヽ'ω`) < 結論から言うと

(ヽ'ω`) < バグでした

root cannot kill process under other users in docker · Issue #6343 · docker/docker · GitHub

CentOS 7の公式リポジトリのはまだ更新されてないから、嫌ならEPELから落としな。 その時、パッケージ名がdockerじゃなくてdocker-ioだから注意しなメーン

とありがたい助言。

(ヽ'ω`) < みんなどうしてんだろう…

この問題について、海外のフォーラムも含めて色々検索していたけど、これだ!ってのがなかなかヒットしなくて、みんな自分の知らない秘伝の技とかもってるのか?やっぱりもう少し早く触っておくべきだったか…とか思ったけど、やっぱりサービスとかじゃなくてフォアで動かしてdetachしてるんですかね?