LoginSignup
18
15

More than 5 years have passed since last update.

[メモ] Dockerでsupervisordを使うときにログを標準出力する

Last updated at Posted at 2017-03-17

Docerの1コンテナ上で複数のサービスを動かす場合、supervisordが便利。
しかし、デフォルトの設定では標準出力、標準エラー出力にログが出力されない。
コンテナ内のログを取得する必要があるとき、利用するには少し辛い。

通常だとサービスの標準出力、標準エラー出力は以下のディレクトリなどに出力されてしまう。(apt-getでsupervisorを入れた場合)
/var/log/supervisor/xxx.log

supervisor_stdout (python2オンリー)を入れる方法もあるが、
https://github.com/coderanger/supervisor-stdout

標準オプションで出力できるので、こちらを使うのがオススメ。
http://veithen.github.io/2015/01/08/supervisord-redirecting-stdout.html

[program:xxx]
...
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

nginxの例

nginxのログを標準出力にシムリンクを貼る

ln -sf /dev/stdout /var/log/nginx/access.log
ln -sf /dev/stderr /var/log/nginx/error.log

/etc/supervisor/conf.d/nginx.conf

[program:nginx]
command=/usr/sbin/nginx -g 'daemon off;'
autostart=true
autorestart=true

stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

これでdocker logやdocker-composeでログが見えるようになりました。

18
15
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
18
15