Docker の実験（その５：コンテナのディスク使用率）

[その４：コンテナの停止および自動起動の設定](https://qiita.com/intrajp/items/a9fcc6fe43c6dc150646)のつづき。

コンテナのディスク使用率を測る方法。
ホストマシンから Docker の容量を確認してみる。

```bash
$ docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          1         1         141.8MB   0B (0%)
Containers      1         1         1.095kB   0B (0%)
Local Volumes   0         0         0B        0B
Build Cache     0         0         0B        0B
```

コンテナの中から、その容量を確認してみる。

```bash
$ docker container exec -it mynginx bash
（以下、コンテナの中）
/# df -h
Filesystem      Size  Used Avail Use% Mounted on
overlay         5.7G  236M  5.5G   5% /
tmpfs            64M     0   64M   0% /dev
shm              64M     0   64M   0% /dev/shm
/dev/sda1       5.7G  236M  5.5G   5% /etc/hosts
tmpfs           2.0G     0  2.0G   0% /proc/acpi
tmpfs           2.0G     0  2.0G   0% /proc/scsi
tmpfs           2.0G     0  2.0G   0% /sys/firmware
```

コンテナの中で、ファイルを作成してみる。

```bash
/# dd if=/dev/zero of=bigfile.txt bs=1M count=500
500+0 records in
500+0 records out
524288000 bytes (524 MB, 500 MiB) copied, 0.611897 s, 857 MB/s
```

コンテナの中で、使用容量が増えていることを確認する。

```bash
/# df -h
Filesystem      Size  Used Avail Use% Mounted on
overlay         5.7G  736M  5.0G  13% /
tmpfs            64M     0   64M   0% /dev
shm              64M     0   64M   0% /dev/shm
/dev/sda1       5.7G  736M  5.0G  13% /etc/hosts
tmpfs           2.0G     0  2.0G   0% /proc/acpi
tmpfs           2.0G     0  2.0G   0% /proc/scsi
tmpfs           2.0G     0  2.0G   0% /sys/firmware
```

ホストマシンから、コンテナの容量の詳細を確認してみる。

```bash
/# exit
$ docker system df -v
Images space usage:

REPOSITORY   TAG       IMAGE ID       CREATED      SIZE      SHARED SIZE   UNIQUE SIZE   CONTAINERS
nginx        latest    3f8a00f137a0   7 days ago   141.8MB   0B            141.8MB       1

Containers space usage:

CONTAINER ID   IMAGE     COMMAND                  LOCAL VOLUMES   SIZE      CREATED          STATUS          NAMES
67df4d402280   nginx     "/docker-entrypoint.…"   0               524MB     18 minutes ago   Up 18 minutes   mynginx

Local Volumes space usage:

VOLUME NAME   LINKS     SIZE

Build cache usage: 0B

CACHE ID   CACHE TYPE   SIZE      CREATED   LAST USED   USAGE     SHARED
```

コンテナのログを確認する。

```bash
$ docker logs mynginx
/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: 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
2023/02/16 10:54:55 [notice] 1#1: using the "epoll" event method
2023/02/16 10:54:55 [notice] 1#1: nginx/1.23.3
2023/02/16 10:54:55 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2023/02/16 10:54:55 [notice] 1#1: OS: Linux 5.15.65+
2023/02/16 10:54:55 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2023/02/16 10:54:55 [notice] 1#1: start worker processes
2023/02/16 10:54:55 [notice] 1#1: start worker process 29
2023/02/16 10:54:55 [notice] 1#1: start worker process 30
<IP_ADDR> - - [16/Feb/2023:10:56:13 +0000] "GET / HTTP/1.1" 200 615 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0" "-"
2023/02/16 10:56:13 [error] 29#29: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: <IP_ADDR>, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "<VM GLOBALIP>:8080", referrer: "http://<VM GLOBALIP>:8080/"
<IP_ADDR> - - [16/Feb/2023:10:56:13 +0000] "GET /favicon.ico HTTP/1.1" 404 153 "http://<VM GLOBALIP>:8080/" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0" "-"
<IP_ADDR> - - [16/Feb/2023:10:57:45 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0" "-"
```

[その６：コンテナの自動削除](https://qiita.com/intrajp/items/110cb53df2bf13e9c889)につづく。