Block IO ,是另一種可以限制容器使用的資源,block IO 指的是磁碟的讀寫,docker 可以 設定權重、限制bps、限制iops
--blkio-weight 600
--device-read-bps /dev/vda:30MB
--device-write-bps /dev/vda:30MB
--device-read-iops /dev/vda:30
--device-write-iops /dev/vda:30
block IO的限額只對 direct IO 有效(不使用檔案快取),在使用dd測試的時候需要加上 oflag=direct
root@docker-lab:~# docker run -it --device-write-bps /dev/vda:30MB ubuntu
root@ac471e09c6f4:/# dd if=/dev/zero of=dd bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 0.0756314 s, 1.4 GB/s
root@ac471e09c6f4:/# dd if=/dev/zero of=dd bs=1M count=100 oflag=direct
100+0 records in
100+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 3.51864 s, 29.8 MB/s
root@docker-lab:~# docker run -it --device-write-iops /dev/vda:20 ubuntu
root@07d2655340d4:/# dd if=/dev/zero of=dd bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 0.0741201 s, 1.4 GB/s
root@07d2655340d4:/# dd if=/dev/zero of=dd bs=1M count=100 oflag=direct
100+0 records in
100+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 9.951 s, 10.5 MB/s