LoginSignup
4
3

More than 3 years have passed since last update.

Docker daemon.jsonにlog max-sizeを指定しても既存テナントには適用されない

Posted at

概要

daemon.jsonを以下のように設定し、Dockerサービスを再起動しても既存コンテナには指定したログサイズで自動ローテーションされない
なので、daemon.jsonだけを設定して安心しているといつの間にかログで圧迫死になりますので、ご注意ください!

どうすればいいのか?

daemon.jsonを設定後に新たに生成したコンテナのみに適用される

コンテナごとにログドライバーの設定が可能なので、コンテナごとに設定値が保持されているのは理解できるが、未指定の場合は、daemon.jsonに従ってほしい気持ちもあります。コンテナの再作成コストはないからこの辺は割り切りでよいかも

検証手順

  1. daemon.jsonを設定し、サービスを再起動(max-size:1k
  2. nginxを起動 (docker run -d nginx)
  3. curl http://localhost
  4. ls -lh /var/lib/docker/containers/<nginxのコンテナID>/<nginxのコンテナID>/<nginxのコンテナID>-json.logのサイズを確認
  5. ログサイズが1kになるまで、手順3を繰り返す
  6. 指定した1k/var/lib/docker/containers/<nginxのコンテナID>/<nginxのコンテナID>/<nginxのコンテナID>-json.log.1が生成されたらOK
  7. daemon.jsonのmax-size:2kに編集し、サービスを再起動
  8. 停止したnginxコンテナをdocker startする
  9. 手順3、4で1kでローテーションしないことが確認できる(予めログを削除しても結果は変わりません)
/etc/docker/daemon.json
{
    "log-driver": "json-file",
    "log-opts": {
      "max-size": "10k",
      "max-file": "2"
    }
}

検証環境

Server Version: 18.09.9-ce
Storage Driver: overlay2
 Backing Filesystem: xfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
runc version: 2b18fe1d885ee5083ef9f0838fee39b62d653e30
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.14.154-128.181.amzn2.x86_64
Operating System: Amazon Linux 2
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.91GiB
Name: hogehoge
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
4
3
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
4
3