注:ロギングは無効ですが、通知は引き続き表示されます!
Dockerコンテナのエラーのみを表示するきちんとしたログが必要ですが、nginxはエラーが発生してもコマンドラインにノイズを注ぎます。すべてを無効にする、これらの通知を無効にするためのエレガントな方法(例:grepをエントリポイントとして使用しない)はありますか?
すでにNGINX_ENTRYPOINT_QUIET_LOGS=1
環境変数、-q
パラメータ、エラーロギングを完全に無効にします。(これはテストの最終目標ではありません。)
$ docker run -e "NGINX_ENTRYPOINT_QUIET_LOGS=1" nginx:alpine "nginx" "-q" "-g" "daemon off; error_log /dev/null emerg;"
2024/02/15 09:38:02 [notice] 1#1: using the "epoll" event method
2024/02/15 09:38:02 [notice] 1#1: nginx/1.25.4
2024/02/15 09:38:02 [notice] 1#1: built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r10)
2024/02/15 09:38:02 [notice] 1#1: OS: Linux 6.7.4-arch1-1
2024/02/15 09:38:02 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1073741816:1073741816
2024/02/15 09:38:02 [notice] 1#1: start worker processes
2024/02/15 09:38:02 [notice] 1#1: start worker process 30
2024/02/15 09:38:02 [notice] 1#1: start worker process 31
2024/02/15 09:38:02 [notice] 1#1: start worker process 32
2024/02/15 09:38:02 [notice] 1#1: start worker process 33
2024/02/15 09:38:02 [notice] 1#1: start worker process 34
2024/02/15 09:38:02 [notice] 1#1: start worker process 35
2024/02/15 09:38:02 [notice] 1#1: start worker process 36
2024/02/15 09:38:02 [notice] 1#1: start worker process 37
2024/02/15 09:38:02 [notice] 1#1: start worker process 38
2024/02/15 09:38:02 [notice] 1#1: start worker process 39
2024/02/15 09:38:02 [notice] 1#1: start worker process 40
2024/02/15 09:38:02 [notice] 1#1: start worker process 41
2024/02/15 09:38:02 [notice] 1#1: start worker process 42
2024/02/15 09:38:02 [notice] 1#1: start worker process 43
2024/02/15 09:38:02 [notice] 1#1: start worker process 44
2024/02/15 09:38:02 [notice] 1#1: start worker process 45
2024/02/15 09:38:02 [notice] 1#1: start worker process 46
2024/02/15 09:38:02 [notice] 1#1: start worker process 47
2024/02/15 09:38:02 [notice] 1#1: start worker process 48
2024/02/15 09:38:02 [notice] 1#1: start worker process 49
2024/02/15 09:38:02 [notice] 1#1: start worker process 50
2024/02/15 09:38:02 [notice] 1#1: start worker process 51
2024/02/15 09:38:02 [notice] 1#1: start worker process 52
2024/02/15 09:38:02 [notice] 1#1: start worker process 53
^C2024/02/15 09:38:04 [notice] 1#1: signal 2 (SIGINT) received, exiting
2024/02/15 09:38:04 [notice] 30#30: exiting
2024/02/15 09:38:04 [notice] 32#32: exiting
2024/02/15 09:38:04 [notice] 33#33: exiting
2024/02/15 09:38:04 [notice] 39#39: exiting
2024/02/15 09:38:04 [notice] 37#37: exiting
2024/02/15 09:38:04 [notice] 40#40: exiting
2024/02/15 09:38:04 [notice] 38#38: exiting
2024/02/15 09:38:04 [notice] 31#31: exiting
2024/02/15 09:38:04 [notice] 42#42: exiting
2024/02/15 09:38:04 [notice] 43#43: exiting
2024/02/15 09:38:04 [notice] 35#35: exiting
2024/02/15 09:38:04 [notice] 34#34: exiting
2024/02/15 09:38:04 [notice] 46#46: exiting
2024/02/15 09:38:04 [notice] 36#36: exiting
2024/02/15 09:38:04 [notice] 45#45: exiting
2024/02/15 09:38:04 [notice] 47#47: exiting
2024/02/15 09:38:04 [notice] 49#49: exiting
2024/02/15 09:38:04 [notice] 48#48: exiting
2024/02/15 09:38:04 [notice] 41#41: exiting
2024/02/15 09:38:04 [notice] 44#44: exiting
2024/02/15 09:38:04 [notice] 51#51: exiting
2024/02/15 09:38:04 [notice] 50#50: exiting
2024/02/15 09:38:04 [notice] 52#52: exiting
2024/02/15 09:38:04 [notice] 53#53: exiting
2024/02/15 09:38:04 [notice] 36#36: exit
2024/02/15 09:38:04 [notice] 33#33: exit
2024/02/15 09:38:04 [notice] 30#30: exit
2024/02/15 09:38:04 [notice] 49#49: exit
2024/02/15 09:38:04 [notice] 41#41: exit
2024/02/15 09:38:04 [notice] 37#37: exit
2024/02/15 09:38:04 [notice] 42#42: exit
2024/02/15 09:38:04 [notice] 43#43: exit
2024/02/15 09:38:04 [notice] 35#35: exit
2024/02/15 09:38:04 [notice] 52#52: exit
2024/02/15 09:38:04 [notice] 31#31: exit
2024/02/15 09:38:04 [notice] 34#34: exit
2024/02/15 09:38:04 [notice] 45#45: exit
2024/02/15 09:38:04 [notice] 44#44: exit
2024/02/15 09:38:04 [notice] 46#46: exit
2024/02/15 09:38:04 [notice] 39#39: exit
2024/02/15 09:38:04 [notice] 50#50: exit
2024/02/15 09:38:04 [notice] 32#32: exit
2024/02/15 09:38:04 [notice] 53#53: exit
2024/02/15 09:38:04 [notice] 40#40: exit
2024/02/15 09:38:04 [notice] 48#48: exit
2024/02/15 09:38:04 [notice] 51#51: exit
2024/02/15 09:38:04 [notice] 47#47: exit
2024/02/15 09:38:04 [notice] 38#38: exit
2024/02/15 09:38:04 [notice] 1#1: signal 14 (SIGALRM) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 40
2024/02/15 09:38:04 [notice] 1#1: worker process 40 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 42 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 42
2024/02/15 09:38:04 [notice] 1#1: worker process 39 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 37
2024/02/15 09:38:04 [notice] 1#1: worker process 37 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 46 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 46
2024/02/15 09:38:04 [notice] 1#1: worker process 32 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 48 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 47
2024/02/15 09:38:04 [notice] 1#1: worker process 47 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 44
2024/02/15 09:38:04 [notice] 1#1: worker process 44 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 50
2024/02/15 09:38:04 [notice] 1#1: worker process 45 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 50 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 45
2024/02/15 09:38:04 [notice] 1#1: worker process 51 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 33
2024/02/15 09:38:04 [notice] 1#1: worker process 33 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 43 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 34 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 34
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 52
2024/02/15 09:38:04 [notice] 1#1: worker process 52 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 31
2024/02/15 09:38:04 [notice] 1#1: worker process 31 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 36
2024/02/15 09:38:04 [notice] 1#1: worker process 36 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 41 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 53 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 49
2024/02/15 09:38:04 [notice] 1#1: worker process 30 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 38 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 49 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 30
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 35
2024/02/15 09:38:04 [notice] 1#1: worker process 35 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: exit
PS:問題はnginxバージョン1.20.0から始まります。バージョン 1.19.10 (最新バージョン 1.19) にはこれらの通知はありませんが、セキュリティの脆弱性のためにこれらの以前のバージョンを使用したくありません。
ただし、変更ログにはこの変更に関する言及はありません。http://nginx.org/en/CHANGES-1.20:
Changes with nginx 1.20.0 20 Apr 2021
*) 1.20.x stable branch.
PPS:このテストを使用してすべてのロギングを無効にしますerror_log /dev/null emerg;
。これらのメッセージは、通常のロギングの外部でnginxによって生成されるようです。
答え1
使用しているDockerイメージは、nginx:alpine
次の行を含むNginx設定を使用します。
error_log /var/log/nginx/error.log notice;
提供された構成ファイルを抽出して変更し、コンテナーを開始し、変更された構成ファイルを正しい場所にインストールする必要があります。
cat /etc/nginx/nginx.conf
コンテナで実行し、出力をファイル(ここでは現在のディレクトリで使用されている)にリダイレクトして、提供されたmy-nginx.conf
設定ファイルを取得します。docker run --rm --entrypoint=cat nginx:alpine /etc/nginx/nginx.conf >my-nginx.conf
お気に入りのエディタを使用して、上記の行の単語を
notice
次のように変更してファイルを編集します。error
これにより、サービスログエラーメッセージまたはメッセージに高い優先順位が与えられます。 GNUを使用すると、sed
次のことができます。sed -i '/^error_log.*notice;/ s/notice/error/' my-nginx.conf
コンテナを起動し、変更された設定ファイルをにマウント(読み取り専用)します
/etc/nginx/nginx.conf
。ここでは、以下をテストしますrun --rm
。docker run --rm -v "$PWD/my-nginx.conf":/etc/nginx/nginx.conf:ro nginx:alpine
ローカルでこれを実行すると、次の出力が表示され、ログレベルが実際にはもう存在しないことを示しますnotice
。
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
Nginx Docker Hubページのカスタム設定セクションも参照してください。https://hub.docker.com/_/nginx
答え2
error_log warn;
生産に使用されます。レベル以上であればnotice
開発に適しています。