如何在Docker中限制IO速度并同时与系统共享文件? [英] How to limit IO speed in docker and share file with system in the same time?

查看:208
本文介绍了如何在Docker中限制IO速度并同时与系统共享文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

暂时使用 -v param,如 / rootfs / shared_dir:/ docker / docker_file

Temporarily, I use -v param like /rootfs/shared_dir:/docker/docker_file.

我的容器在文件夹中创建一些数据文件,我想与我的系统共享文件夹。

My container create some data file in the folder, And I want share the folder with my system.

此外,我想限制docker容器中的IO速度。我该怎么做?

Also I want to limit the IO speed in the docker container. How can I do this?

推荐答案

版本1.10后,Docker添加了新功能来操纵容器中的IO速度。

After version 1.10 docker added new features to manipulate IO speed in the container.

~$ 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

for example if you want to limit write speed to 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

without limit my speed is 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

这篇关于如何在Docker中限制IO速度并同时与系统共享文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆