Help us understand the problem. What is going on with this article?

/var/lib/docker/containers の容量が多いとき、docker hostがdisk 100%になったときの対処法

原因のコンテナを探す

まず容量が多いcontainerを探す。80Gのやつがいる。

[root /]# du -ha --max-depth=1 /var/lib/docker/containers
32K /var/lib/docker/containers/a4aba1c80836238c75700566d9b3bfcebba0051c90bffc55bc18258eda0bf091
40K /var/lib/docker/containers/e812ac8bf89a9310090bd49922312cf8883ff687e88c853e93895ac2aa97f3c7
64K /var/lib/docker/containers/2a1b2540bd28e882d759a87b83cc209f65bfb1605fb2c5c07fdb831a26e8ad3b
672K    /var/lib/docker/containers/341ed988466fa070613740b39eed4ed8fc565874fbb96d4d8e7e1be325db0a66
80G /var/lib/docker/containers
80G /var/lib/docker/containers/5f678d8b7aad742b94c31288094b5bcecca2cb379c5093ffb1d0165b0e8f689d

このhashが何のコンテナ?はこれでわかる

 docker container inspect 5f678d8b7aad742b94c31288094b5bcecca2cb379c5093ffb1d0165b0e8f689d | grep -i name

で、コンテナ自体のvolumeは10G固定なんで、なんで80Gあるかというと

[root@:/var/lib/docker/containers/5f678d8b7aad742b94c31288094b5bcecca2cb379c5093ffb1d0165b0e8f689d]# ll
-rw-r----- 1 root root 80G 2019-03-13 14:25:27 5f678d8b7aad742b94c31288094b5bcecca2cb379c5093ffb1d0165b0e8f689d-json.log

こいつlogが多いんすね。

logをへらす方法

logging optionを使います。docker-composeのv3からだけ使えます。

# cat docker-compose.yml
version: '3'

services:
  web:
    image: <image>
    logging:
      driver: "json-file"
      options:
        max-size: "200M"
        max-file: "1"

logging option

Specify logging options for the logging driver with the options key, as with the --log-opt option for docker run.
Logging options are key-value pairs. An example of syslog options:

options:
  max-size: "200k"
  max-file: "10"

https://docs.docker.com/compose/compose-file/#logging

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした