Docker and JMeter
How to leverage Docker containerization for Apache JMeter testing, including standalone, server, and distributed testing modes.
Mark
Performance Testing Expert
With more and more test environments moving to the cloud it makes sense to embrace the cloud and consider how we can take advantage of it. Containerization technology can be leveraged for Apache JMeter testing in cloud environments.
Docker Image Setup
Rather than building a custom image, use the pre-built Docker image egaillardon/jmeter from Docker Hub:
docker pull egaillardon/jmeter
Execution Modes
JMeter can operate in three modes within containers:
- Standalone - Interactive or detached
- Server mode - Running as a JMeter server
- Distributed testing mode - Controller with remote servers
Code Examples
Interactive Standalone
Run JMeter interactively with output visible in the terminal:
docker run --interactive --tty --rm --volume `pwd`:/jmeter egaillardon/jmeter --nongui --testfile test.jmx --logfile result.jtl
Detached Standalone
Run JMeter in the background:
docker run --detach --rm --volume `pwd`:/jmeter egaillardon/jmeter --nongui --testfile test.jmx --logfile result.jtl
Server Mode
Run JMeter as a server for distributed testing:
docker run --detach --publish 1099:1099 --rm egaillardon/jmeter -Jserver.rmi.ssl.disable=true -Djava.rmi.server.hostname=192.168.1.1 -Jserver.rmi.localport=1099 --server
Distributed Client
Run the JMeter controller connecting to remote servers:
docker run --detach --rm --volume `pwd`:/jmeter egaillardon/jmeter -Jserver.rmi.ssl.disable=true --nongui --testfile test.jmx --remotestart 192.168.1.1 --logfile result.jtl
Key Parameters
| Parameter | Description |
|---|---|
--interactive | Keep STDIN open |
--tty | Allocate a pseudo-TTY |
--rm | Remove container after exit |
--volume | Mount local directory |
--detach | Run in background |
--publish | Expose port |
-Jserver.rmi.ssl.disable=true | Disable RMI SSL |
-Djava.rmi.server.hostname | Set RMI hostname |
Conclusion
Containerization enables rapid deployment and dynamic scaling of JMeter slaves for performance testing scenarios requiring higher thread counts. This approach simplifies infrastructure management and allows for consistent, reproducible test environments.
Further Reading
Tags: