在docker容器中不能使用tc

我正在使用tc来限制docker容器中的发送速率。 将下面的脚本添加到Dockerfile中:

tc qdisc add dev eth0 root handle 1: htb default 2 tc class add dev eth0 parent 1:1 classid 1:2 htb rate 2mbit ceil 2mbit prio 2 tc qdisc add dev eth0 parent 1:2 handle 2: sfq perturb 10 tc filter add dev eth0 protocol ip parent 1:0 u32 match ip dst 192.168.1.124 flowid 1:2 

通过以下命令在root帐户下运行docker:

 docker run --cap-add=NET_ADMIN --name lqt_build -d -p 8443:8443 -p 443:443 -p 3478:3478 lqt_build 

但它仍然显示这个错误:

 Step 25 : RUN cd /usr/share/ta/ && sudo ./tt rate ---> Running in fb6a4477ad6c RTNETLINK answers: Operation not permitted RTNETLINK answers: Operation not permitted RTNETLINK answers: Operation not permitted RTNETLINK answers: Operation not permitted We have an error talking to the kernel [8] System error: read parent: connection reset by peer 

看起来,内核阻止容器中的应用程序改变一些内核设置,即使它们以root身份运行。 我猜容器没有自己的内核,而是运行在与其他容器共享的内核上,所以不能让它触及底层内核的设置。 有没有人有这个问题的经验?

根本原因是在Dokcerfile中使用tc。 NET_ADMINfunction当时不会生效。 在docker容器运行后,Tc命令正常工作。 感谢user2915097。