JMeter – Distributed Load Testing using Docker

A single JMeter instance might not be able to generate enough load to stress test your application. As this site shows, one JMeter instance will be able to control many other remote JMeter instances and generate larger load on your application. JMeter uses Java RMI [Remote Method Invocation] to interact with objects in a distributed network.

JMeter master and slave communicate as shown in the below picture.


We need to open 2 ports for each Slave/Server.


Open a port in client machine for slaves to sends the results to master.


By running multiple instances of JMeter as server in multiple machines we can generate as much load as we need.

JMeter-Docker-Basic - New Page


What is the use of docker here?

Docker is a bit like a virtual machine. But unlike a virtual machine, rather than creating a whole virtual operating system, Docker allows applications to use the same Linux kernel as the system that they’re running on and only requires applications be shipped with things not already running on the host computer. This gives a significant performance boost and reduces the size of the application – source:

Docker is a manager of Infrastructure. It will be able to package a software and all its dependencies to run as a container. You can deploy the software, packaged as a docker image, in any machine where docker is installed. It, kind of, separates the software from the hardware – so the developer can rest assured that the application will run on any machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

Docker’s role in JMeter Distributed Testing:

If we look at the above setup – to do distributed load testing – we need 1 master & we need N number of slaves to generate huge load. Each and every JMeter slave machine needs to have specific version of Java and JMeter installed. Specific ports should be opened and JMeter server should be running, ready and waiting for the master to send the instruction.

Setting up few machines manually might look easy. What if we have to do this for 50, 100, 1000 machines? Also imagine what will happen if we need to upgrade JMeter versions in all the machines in future!! That is where docker comes into picture.

We basically setup the whole infrastructure for JMeter distributed testing in a file called Dockerfile. Check these dockerfiles and read the comments to understand what each step does.

Dockerfile for JMeter Base:

In distributed testing all the environment are expected to have same version of Java, JMeter, plugins etc. Only difference between the master and slave would be the ports which are exposed and process running. So, Lets create a Dockerfile for JMeter-base image.


Dockerfile for JMeter Client / Master:

Master docker file should be inherited from the base image and should expose port 60000.


Dockerfile for JMeter Server / Slave:

Server docker file should be inherited from the base image and should expose port 1099 and 50000. jmeter-server should be running.


As you see in the above Dockerfile, if we need to change the Java / JMeter version / port, I just need to update the dockerfile and Docker will take care of the rest.

I have pushed these dockerfiles into docker hub under vinsdocker account. So anyone will be able to pull those files and set up the JMeter distributed testing infrastructure.

  • Ensure that docker is installed in your machine. Once it is installed, the rest is easy. You just need to follow the steps here.
  • Run below commands one by one.
sudo docker run -dit --name slave01 vinsdocker/jmserver /bin/bash
sudo docker run -dit --name slave02 vinsdocker/jmserver /bin/bash
sudo docker run -dit --name slave03 vinsdocker/jmserver /bin/bash

Docker will automatically pull the docker image I have uploaded and create 3 containers for JMeter server. If you need more containers, keep executing above command just by changing the container name.

  • Run the below command to create a container for JMeter master.
sudo docker run -dit --name master vinsdocker/jmmaster /bin/bash
  • Run below command to see all the running containers and ports opened etc.
sudo docker ps -a


  • Run the below command to get the list of ip addresses for these containers.
sudo docker inspect --format '{{ .Name }} => {{ .NetworkSettings.IPAddress }}' $(sudo docker ps -a -q)


  • I create a very simple JMeter test plan to test the setup with 5 threads – scheduled to run for 120 seconds.



  • By issuing below command, I copy the test into my JMeter master container. This command will copy my local jmeter test (docker-test.jmx) into the master container in this path: /jmeter/apache-jmeter-2.13/bin/docker-test.jmx
sudo docker exec -i master sh -c 'cat > /jmeter/apache-jmeter-2.13/bin/docker-test.jmx' < docker-test.jmx
  • Go inside the container with the below command and we can see if the file has been copied successfully.
 sudo docker exec -it master /bin/bash


  • Lets run the test in master to see if it works fine [not in distributed mode]. Docker container will be able to run the JMeter test as it has all the softwares & dependencies to run the JMeter test.


  • That’s it. We are now ready for running our test in distributed using docker containers. We just need to append -R[slave01,slave02,slave03]



If you had noticed, we create all the containers in the same host. Ie, the JMeter and JMeter slaves are all running in the same machine. So the all the system resources would be shared by these containers.



In this post, our aim was to use Docker to create the JMeter distributed testing infrastructure. If you had followed the above steps, you would have understood that creating the test infrastructure using docker is very easy and fast. We write the whole infrastructure in a file which can be version controlled. Then we create an instance (container) from the file. Docker ensures that the container has all the softwares and dependencies etc.

You might ask if it is ok to run multiple jmeter server instances in one machine to generate more load! No, It is not OK. It will not help at all. In fact, One instance of JMeter will be able to generate more load than running multiple instances of JMeter in the same host.

So why did we use docker and do all these?

As I said above,  our aim here is to understand how docker works in JMeter testing. We can understand the real use of docker when we use AWS/digitalocean, cloud computing service providers, where you can create any number of VMs on demand. We will see that in the next post!


Happy Testing & Subscribe 🙂



Note: If you have any questions related to docker install, I request you to raise that in StackOverFlow.


Share This:

Categories: Articles, AWS / Cloud, Best Practices, CI / CD / DevOps, Distributed Load Test, Docker, Framework, JMeter


Leave a Reply

Your email address will not be published. Required fields are marked *