使用tc来限制Docker容器的传出网络带宽 [英] Use tc to throttle Docker container's outgoing network bandwidth

查看:1361
本文介绍了使用tc来限制Docker容器的传出网络带宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对Docker容器进行带宽调节。
为了限制下行链路带宽,我可以先找到容器的veth接口并使用tc: tc qdisc add dev vethpair1 root tbf rate 1mbit latency 50ms burst 10000 。如果我想限制上行链路带宽,我需要指定 - cap-add = NET_ADMIN ,当我旋转容器并在<$ c $上使用相同的tc命令c> eth0 在容器内。有没有任何非侵入式的方式来做,所以我可以管理任何容器而不赋予它特权?

I'm trying to do the bandwidth throttling to the Docker containers. To limit the downlink bandwidth, I can first find the veth interface of the container and use tc: tc qdisc add dev vethpair1 root tbf rate 1mbit latency 50ms burst 10000. If I want to limit the uplink bandwidth, I need to specify --cap-add=NET_ADMIN when I spin up the container and use the same tc command on eth0 inside the container. Is there any non-intrusive way to do it, so that I can administrate any container without giving it privilege?

推荐答案

你可以告诉Docker在引擎盖下使用LXC:使用 -e lxc 选项。

You could tell Docker to use LXC under the hoods : use the -e lxcoption.

Create your containers with a custom LXC directive to put them into a **traffic class** :

`docker run --lxc-conf="lxc.cgroup.net_cls.classid = 0x00100001" your/image /bin/stuff` 

检查官方文档,了解如何

注意: - storage-driver = devicemapper -e lxc 选项适用于Docker 守护程序,而不是运行 docker run ....时使用的Docker客户端。 ...

Note : the --storage-driver=devicemapperand -e lxcoptions are for the Docker daemon, not for the Docker client you're using when running docker run ........

还可以这样做:

mkdir /var/run/netns
ln -sf /proc/`docker inspect -f '{{ .State.Pid }}' YOUR_CONTAINER`/ns/net /var/run/netns/SOME_NAME
ip netns exec SOME_NAME iptables -L -nv

这篇关于使用tc来限制Docker容器的传出网络带宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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