Skip to content

Instantly share code, notes, and snippets.

@hlfshell
Created December 3, 2020 23:08
Show Gist options
  • Save hlfshell/0373dbcaefe37c1c80c16d21fa10c62d to your computer and use it in GitHub Desktop.
Save hlfshell/0373dbcaefe37c1c80c16d21fa10c62d to your computer and use it in GitHub Desktop.
Network Testing a Docker Application

Network testing a Docker Container with pumba + tc

Alright, so you want to test how your application fares with questionable network reliability. If you can get your application running in a docker container, this write-up will have you covered.

We're going to utilize linux's tc to control the outbound network connection. There's no easy way to do inbound yet. From that we'll be able to throttle and drop packets outbound which should give you a fair test of unreliable networks.

Dockerfile

This dockerfile utilizes the ubuntu image which was necessary for my purposes, but can be generalized to other docker imagers as per your use case.

FROM ubuntu

RUN apt-get update
RUN apt-get install -y ca-certificates iproute2

# -----
# The rest of your docker file
# -----

The important bit to notice here is that we install iproute2 (and, depending on whom you're communicating with, you may need ca-ceritifcates for certain SSL connections) onto the container. This installs tc.

Pumba

Download the excellent tool pumba. Set it up on your path.

Run the container

Assuming that you build your image with

docker build . -t my_image

you can run

docker run --name=network_test my_image

Once this is working, initiae your test. Use the pumba command to begin your network throttling:

pumba netem --duration 5m delay --time 3000 loss --percentage 30 corrupt --percent 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment