如何获得正确的设备来限制 docker 容器的块 IO?

How to get the correct device to limit block IO for docker container?

我需要限制一些 docker 容器的块 IO 操作速度。

为此,我需要执行以下操作: docker run -it --device-read-bps /dev/sda:1mb ubuntu,根据docs.

我的问题是如何为每个容器获取正确的设备来设置限制?有什么可以通过 docker inspect 获取此信息?

docker inspect my_container | grep DeviceName returns什么都没有?

df -h的输出是:

Filesystem            Size  Used Avail Use% Mounted on
devtmpfs              7.9G     0  7.9G   0% /dev
tmpfs                 7.9G     0  7.9G   0% /dev/shm
tmpfs                 7.9G  1.4M  7.9G   1% /run
tmpfs                 7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/mapper/vg0-data   31G  6.9G   23G  24% /
tmpfs                 7.9G     0  7.9G   0% /tmp
/dev/sda3             283M   27M  238M  11% /boot
/dev/sda2              10M  2.2M  7.9M  22% /boot/efi
/dev/sdb1              63G  198M   60G   1% /mnt/data
overlay                31G  6.9G   23G  24% /var/lib/docker/overlay2/0c917cf591efb40f75a450b6ad93bf9cf06c91f7f625e1f073887031d152f444/merged
shm                    64M     0   64M   0% /var/lib/docker/containers/b21b4b5d27bd57f04204d3a54f11930a532bdc8c56cabfe903f34b955f3c81f1/mounts/shm
overlay                31G  6.9G   23G  24% /var/lib/docker/overlay2/8b198c4829d4eb13c21e7c9d1be99aa00986d64f13f50a454abc539aed37e759/merged
shm                    64M     0   64M   0% /var/lib/docker/containers/1667192b0b8026eb517894fdf72f71c6aca5a0ff78648447c12175c96b76990c/mounts/shm
overlay                31G  6.9G   23G  24% /var/lib/docker/overlay2/72efa8bcdec2c529ca3ebde224f8d14e22780636c614fe45a0228eb957a99351/merged
shm                    64M     0   64M   0% /var/lib/docker/containers/a7123dfebcc42a675b6ccb0435df1cc24bcd0a39847fb4cb5a3fdcaf2d38089f/mounts/shm
overlay                31G  6.9G   23G  24% /var/lib/docker/overlay2/65ede56c537f5de766f616f13df90aae46f287b9e28703496f90af9f74f4c463/merged
shm                    64M     0   64M   0% /var/lib/docker/containers/6a24ef7116078d48fde87fc47a8efd194ef541ffb7d85ae4bec34e5086e46d4b/mounts/shm
overlay                31G  6.9G   23G  24% /var/lib/docker/overlay2/2b444d99740719500285bd94eb389815e631cd183cf3637e64fa40999ccf2530/merged
shm                    64M     0   64M   0% /var/lib/docker/containers/8c7300dcd9981878ce46f4b805d65b72bf3afbf87d9510312ba5110b95ae8cf4/mounts/shm
overlay                31G  6.9G   23G  24% /var/lib/docker/overlay2/9ea1ad005bcbcdb0e52d6f2b05568268e3a6e318f8d30986e0fac56523408e89/merged
shm                    64M     0   64M   0% /var/lib/docker/containers/5eb12be6805976d230f5ec17bda65100745bebeccea4ab7c2bcf2260405ecb96/mounts/shm

我看到很多帖子问这个问题,比如 this,但没有给出确定的答案。

Docker 没有指定一种方法来谨慎地获取块设备,它用于 read/write 操作。

成功的解决方法:

  • 获取OS(OS依赖命令)的所有块设备。
  • 对所有设备设置限制。没有观察到副作用。