Thanks to this question, I realized that you can run tc qdisc add dev eth0 root tbf rate 1mbit latency 50ms burst 10000in a container to set its download speed to 1 megabyte / s.
Here is an example Docker file that demonstrates this by creating a random file and loading it into / dev / null-as-a-service at an approximate download speed of 25 KB / s:
FROM ubuntu
RUN apt-get update
RUN apt-get install -y iproute curl
RUN head -c 2M </dev/urandom > /upload.data
RUN echo "#!/bin/bash" >> /upload.sh
RUN echo "tc qdisc add dev eth0 root tbf rate 25kbps latency 50ms burst 2500" >> /upload.sh
RUN echo "curl -d @/upload.data http://devnull-as-a-service.com/dev/null" >> /upload.sh
RUN chmod a+x /upload.sh
ENTRYPOINT exec /upload.sh
Assuming you have this Docker file inside a directory with a name ratelimitthat is in your current working directory, you can run it with:
docker build ratelimit -t ratelimit && docker run --cap-add=NET_ADMIN ratelimit
The option --cap-add=NET_ADMINallows the container permission to change its network interface. You can find the documentation here .
Dockerfile , . iproute tc, curl , . 2 . script, . , , script , , .
Token, 25 /. , Token Bucker, .
Docker , cURL ( , , ).