暂时,我使用-v param像/ rootfs / shared_dir:/ docker / docker_file.
我的容器在文件夹中创建了一些数据文件,我想与我的系统共享该文件夹.
另外,我想限制docker容器中的IO速度.我怎样才能做到这一点?
最佳答案
版本1.10之后,docker添加了新功能来操纵容器中的IO速度.
~$docker help run | grep -E 'bps|IO'
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
--blkio-weight Block IO (relative weight),between 10 and 1000
--blkio-weight-device=[] Block IO weight (relative device weight)
--device-read-bps=[] Limit read rate (bytes per second) from a device
--device-read-iops=[] Limit read rate (IO per second) from a device
--device-write-bps=[] Limit write rate (bytes per second) to a device
--device-write-iops=[] Limit write rate (IO per second) to a device
例如,如果要将写入速度限制为50 MB / s
$docker run -it --rm --device-write-bps /dev/sda:50mb ubuntu /bin/bash
root@e88db9cb1263:/# time dd if=/dev/zero of=test.out bs=1M count=1024 oflag=direct
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied,20.4334 s,52.5 MB/s
real 0m20.437s
user 0m0.016s
sys 0m0.472s
没有限制我的速度是291 MB / s
~$docker run -it ubuntu bash
root@2911226bd75e:/# time dd if=/dev/zero of=test.out bs=1M count=1024 oflag=direct
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied,3.69373 s,291 MB/s
real 0m3.696s
user 0m0.004s
sys 0m0.496s