発生したエラー
MySQL 5.7 のイメージ
を使用して単純に起動しても下記エラーが発生して、初期化処理に失敗していた。
厳密には初期化時に上記エラーが出て、初期化SQLまでたどり着かなかった。
初期化処理に失敗すると、mysql userの設定や admin パスワードの設定がうまくできないようで、どうしようもない状態になるようで、、これをなんとかしたかった…
/usr/local/bin/docker-entrypoint.sh: line 137: 126 Killed "$@" --skip-networking --default-time-zone=SYSTEM --socket="${SOCKET}"
ログをみると怪しい部分は上記のみで、どうもプロセスがいきなり Kill されているように見える
原因はリソースの使いすぎ
以下のようなコメントにたどり着いた
1708115 – Running mysql container in moby-engine results in 100% memory usage
Really high memory usage · Issue #579 · docker-library/mysql
Thank you so much @evolbug! The bug you found put me on the right tracks. The issue is caused by the ulimit nofile. By default, on arch, the value is too low I guess. running the container with --ulimit nofile=262144:262144 solve the issue and mysql behaves normally. I guess the best way to fix this would be to set this option by default. Should this be documented on docker images prone to this issue? Edit: Actually, it's weird, I think the default limit is way to high, this is what I get by default: > docker run --rm centos:7 /bin/bash -c 'ulimit -Hn && ulimit -Sn' 1073741816 1073741816 So lowering the value fixes the issue
The ulimits does the trick. I added this to my docker-compose and make it work. @vodkhard
ulimits: nproc: 65535 nofile: soft: 26677 hard: 46677
結論: ulimits でリソース制限してやる
ulimits:
nproc: 65535
nofile:
soft: 26677
hard: 46677
ulimit メモ
ulimits
は Linux のコマンドで、ユーザが使用できるリソースを制限できるもの。ファイル最大サイズや、使用メモリ、使用プロセス数などを制限できるnproc
は プロセス数の制限nofile
は プロセスが同時に開けるファイルディスクリプタの数soft
は一般ユーザの上限値、hard
は root ユーザの上限値
ulimit -a
で現在設定されている値を表示できる$ ulimit -a real-time non-blocking time (microseconds, -R) unlimited core file size (blocks, -c) unlimited data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 126012 max locked memory (kbytes, -l) 8192 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 126012 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited