Skip to content

Instantly share code, notes, and snippets.

@dnephin
Created August 5, 2015 19:01
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnephin/73dc7476e3ca15bffbca to your computer and use it in GitHub Desktop.
Save dnephin/73dc7476e3ca15bffbca to your computer and use it in GitHub Desktop.
docker_tc - using tc with a docker container
#!/bin/bash
#
#
#
set -eu
DOCKER_RUN_PATH=/var/run/docker/execdriver/native/
STATE_JSON=state.json
container=$1
id="$(docker inspect -f '{{ .Id }}' $container)"
state_file="$DOCKER_RUN_PATH/$container/$STATE_JSON"
veth="$(cat $state_file | jq -r '.config.networks[].host_interface_name' | grep veth)"
# Example just with 30% loss
tc qdisc replace dev $veth root netem loss 40%
# Example drop
tc qdisc replace dev $veth root netem delay 75ms 100ms distribution normal
# Example restore
tc qdisc del dev $veth root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment