LoginSignup
43
41

More than 5 years have passed since last update.

Dockerコンテナのファイルディスクリプタ設定

Last updated at Posted at 2014-03-01

やりたいこと

fluentdを使うにはファイルディスクリプタ(FD)の数を増やしておく必要がある。これをdockerコンテナに対して設定したい。しかしこれは残念ながらホスト側やdocker側の設定が必要になりDockerfileには書けない。ここを参考に設定してみた。fluentdに限った設定ではないので、いろいろな用途に使えるはず。

とりあえずこうしてる

どなたかもっとよい手順があれば教えてくだされ。

  • ホスト:Debian 7 on Google Compute Engine
  • ゲスト:Ubuntu 12.04
  • Docker v0.8.1

ホスト側のFDを増やす

/etc/security/limits.confでFDを増やしても自動起動スクリプトには効いてくれないので困っていた。外道父さんのエントリを参考に、/etc/initscriptを以下のように書いて追加したらうまく動いた。外道父さんthx!

ulimit -n 65536
eval exec "$4"

カーネルパラメータ調整

これはfluentd/td-agentを使う場合のみ。

/etc/sysctl.conf
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 10240    65535

dockerコンテナのFDを増やす

/etc/init/docker.conf
limit nofile unlimited unlimited

ホストを再起動してFDが増えてるか確認

$ sudo docker run ubuntu sh -c 'ulimit -n'

これで65536と出ればOK。

43
41
0

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
43
41