Cloud Native 5 min read

Deploying Locust Distributed Load Testing with Docker Containers

This article explains how to containerize Locust's distributed load‑testing mode using Docker, detailing image design, environment‑variable configuration, master‑slave networking, and example commands to run a scalable testing setup on Linux systems.

360 Quality & Efficiency
360 Quality & Efficiency
360 Quality & Efficiency
Deploying Locust Distributed Load Testing with Docker Containers

Background Installing Locust on a Linux kernel requires many C/C++ dependencies; to reduce deployment cost, Docker containers are used to package Locust and its libraries.

Docker provides process, file‑system, and network isolation on Linux (x64) via user‑space mechanisms, enabling lightweight containers that communicate through a virtual bridge (docker0).

Solution

1. Distributed Mode – Locust runs in a master‑slave configuration; the only difference is the command‑line argument, so a single Docker image can serve both roles.

2. Image Design – The base image installs locustio and required packages. The final Locust image receives the scenario file path, mode (master or slave), target URL, and master IP via environment variables at container start, allowing dynamic configuration.

3. Dockerfile – A Dockerfile (shown in the original images) builds the Locust image with the necessary dependencies and copies the test scripts into /home/locust/.

4. run.sh Script – A custom startup script (adapted from a GitHub project) sets all parameters through environment variables, which Docker passes to the container at launch.

5. Networking – Master and slave containers communicate over port 5557 (customizable). If both run on the same host, Docker’s parent‑child container relationship allows the child to access any port of the parent. For separate hosts, the -p flag maps the master’s port to the host, enabling remote access.

6. Start Commands (same machine)

docker run --name locustmaster -v /home/like/locustDocker/src/:/home/locust/ -e LOCUST_MODE=master -e TARGET_URL=http://www.so.com -e SCENARIO_FILE=/home/locust/main.py -p 8089:8089 [image id]
docker run -v /home/like/locustDocker/src/:/home/locust/ --link locustmaster:lm -e LOCUST_MODE=slave -e TARGET_URL=http://www.so.com -e SCENARIO_FILE=/home/locust/main.py -e MASTER_HOST=172.17.0.2 --name locustclient1 -d [image id]

The --link option creates an alias ( lm) for the master container, simplifying address resolution.

7. Actual Run

System resources: 4 CPU, 4 GB RAM. Test configuration: 1 master, 4 slaves, 500 users, think time 100 ms, target URL http://www.so.com. The performance observed inside containers was comparable to running Locust directly on the host, indicating the containerized approach is viable.

8. Results – Screenshots (included in the original article) show the Locust web UI and test metrics.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockercontainerizationDistributedLocust
360 Quality & Efficiency
Written by

360 Quality & Efficiency

360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.