大家在用docker run -it  --rm  --device-write-bps /dev/sda:3m  XX /bin/bash时, 进入docker后 ,用dd验证一下参数是否起作用了。

# dd if=/dev/zero of=test.out bs=1M count=20 oflag=direct

但是结果远远超出3M/s。 如果你遇到这样的问题 ,请往下看::

 --device-write-bps  的正确使用:

# docker run -it --rm --device-write-bps /dev/dm-1:3m  XX /bin/bash
# dd if=/dev/zero of=test.out bs=1M count=20 oflag=direct


或者
# docker run -it --rm --device /dev/sda --device-write-bps /dev/sda:3m  XX /bin/bash
# dd if=/dev/zero of=/dev/sda bs=1M count=20 oflag=direct


一定要将要限制的设备写对(进入docker环境后, 用df -h )
其中 --device-write-bps 对应内核接口的blkio.throttle.write_bps_device
要想docker中的该参数生效 /cgroup/blkio/docker/7f13c605d6e28e61de9cdf04353b8939db657500328ed830c607d2063fe9fa7a/blkio.throttle.write_bps_device 中值要正确, 

/cgroup/blkio/blkio.throttle.write_bps_device  文件只对物理机起作用, 不影响docker

[root@isoft ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
isoft1              5.0                 cf238f8e8aee        5 days ago          359.8 MB
[root@isoft ~]# docker run -it --rm  --device-write-bps /dev/dm-1:3m cf238f8e8aee /bin/bash
[root@56bb5c48de60 /]# df -h 
Filesystem            Size  Used Avail Use% Mounted on
rootfs                9.8G  400M  8.9G   5% /
/dev/mapper/docker-8:3-130787-4260529dda4787737fcddcf1f37d7fb37ffc6d834f89b0ff25634c7fa5a3fdda
                      9.8G  400M  8.9G   5% /
tmpfs                 3.8G     0  3.8G   0% /dev
tmpfs                 3.8G     0  3.8G   0% /sys/fs/cgroup
/dev/sda3              20G   13G  5.4G  71% /run/secrets
/dev/sda3              20G   13G  5.4G  71% /etc/resolv.conf
/dev/sda3              20G   13G  5.4G  71% /etc/hostname
/dev/sda3              20G   13G  5.4G  71% /etc/hosts
shm                    64M     0   64M   0% /dev/shm
tmpfs                 3.8G     0  3.8G   0% /proc/kcore
tmpfs                 3.8G     0  3.8G   0% /proc/timer_stats

再开一个终端查看 确认docker设备, 
[root@isoft ~]# ls /dev/mapper/docker-8:3-130787-5cf05b63b3734784b625fda7f4ab0e525d1316fa1bf51f5a614e9531b1c05860 -l
lrwxrwxrwx 1 root root 7 7月  10 13:59 /dev/mapper/docker-8:3-130787-5cf05b63b3734784b625fda7f4ab0e525d1316fa1bf51f5a614e9531b1c05860 -> ../dm-1


Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐