Bean Network Tester

Simulate network latency in Docker and Docker Compose

Add delay, packet loss or a speed limit to one container's traffic, without changing its image and without a proxy in front of it. The Bean Network Tester image joins that container's network and changes only what goes in and out of it, then stops on its own. It is the Linux package, so it is experimental.

Slow down one container

Start the image next to the container you want to test, here one named api. It needs three capabilities on top of Docker's defaults, and no --privileged:

docker run --rm --network container:api --cap-add BPF --cap-add PERFMON --cap-add NET_ADMIN \
  ghcr.io/donislawdev/beannetworktester:1.1.0 --dst-ip 203.0.113.10 --latency 100 --duration 60

--network container:api puts the program into that container's network. It reaches every program in that network, including any other container started in it the same way, and never the host or containers with a network of their own. --dst-ip narrows it to one address. Without it every connection of api is slowed. Measured: at --latency 100 the container's ping to the address rose from 0.07 ms to 200.8 ms, because the request and the reply are both delayed, and its ping to another address stayed under 1 ms.

Every setting of the command line works here: --loss, --jitter, --down and --up for a speed limit, a preset or a whole scenario. --duration ends the session, and so does docker stop.

Docker Compose: simulate network latency for a service

In Compose the same thing is a service of its own that shares the network of the one it slows down:

services:
  api:
    image: your-api-image
  slow-network:
    image: ghcr.io/donislawdev/beannetworktester:1.1.0
    network_mode: "service:api"
    cap_add: [BPF, PERFMON, NET_ADMIN]
    command: ["--latency", "200", "--loss", "2", "--duration", "300"]

Every service that talks to api now sees it 400 ms further away, and 2 % of the packets lost. Measured with this file: the ping from another service rose from 0.1 ms to 401 ms. docker compose stop slow-network ends it, and the traffic is normal at once.

One program inside a container

--target picks a program by name, as on a desktop. To see the processes of another container, the image also needs its process list: --pid container:api.

docker run --rm --network container:api --pid container:api \
  --cap-add BPF --cap-add PERFMON --cap-add NET_ADMIN \
  ghcr.io/donislawdev/beannetworktester:1.1.0 --target nginx --latency 100 --duration 60

Without --pid the program finds no such process and says so in its log: Targeting: NO matching process has a connection open - traffic is NOT being impaired. Nothing is slowed in that case.

A program on the Linux host

The image can also reach a program that runs on the host itself, outside any container. It needs the host's network and process list, and two more options: reading the connections of a program outside the container is refused without both of them.

docker run --rm --network host --pid host \
  --cap-add BPF --cap-add PERFMON --cap-add NET_ADMIN \
  --cap-add SYS_PTRACE --security-opt apparmor=unconfined \
  ghcr.io/donislawdev/beannetworktester:1.1.0 --target firefox --latency 100 --duration 60

With --network host the session changes the host's own traffic, your ssh session included, so keep it narrow with --target, --dst-ip or --dst-port, and short with --duration. Measured on Ubuntu 26.04: the targeted program's requests went from 3 ms to about 250 ms, and another program's stayed at 11 ms. On a desktop the Linux package does the same without Docker.

Docker Desktop on Windows and macOS

Docker Desktop runs containers in a Linux virtual machine of its own, and there "host" means that machine. The image changes the traffic of containers, never that of Windows or macOS programs. To slow down a Windows program, use the Windows version of Bean Network Tester.

On a Mac with Apple silicon, and on other arm64 machines, Docker runs this x86_64 image under emulation, and a capture may not work there. Measured on an M2 Mac with Colima's QEMU emulation: the image starts and --simulate works, but a capture stops at once with Function not implemented, while --doctor still reports every row OK.

Files, scenarios and CI

Which images there are

Every stable release from 1.1.0 on is an image, tagged with its version and latest. Release candidates get none. Each is the published Linux package, unchanged, on Ubuntu 24.04, for x86_64. Before it is pushed, the package's checksum and build provenance are checked, and the image is run on a Linux kernel the way this page describes. To check an image you pulled:

gh attestation verify oci://ghcr.io/donislawdev/beannetworktester:1.1.0 --owner donislawdev --predicate-type https://slsa.dev/provenance/v1

Ready to break your own network on purpose?

Download