Docker – JMeter Integration
Docker – JMeter Integration
Installing Docker
Docker must be installed as a service on the host machine that executes the containers. The best way to perform docker command is via command shell locally or remotely. Check out this link to see which version you should install.
All the examples brought here will be compatible with Docker Community Edition, which can be downloaded directly from this link. If you have an older version of Windows or Mac that does not have the necessary kernel feature, you can find it in the Docker Toolbox package that provides a minimal environment to work with Docker by using a Linux host machine running on VirtualBox.
After correctly installing the Docker package, it’s possible to interact with Docker by using the command line. The command’s basic structure is:
docker [command] <parameters>
The available list of commands is long and complex. In this paper we will focus on a few commands included in the table below:
Command | Description |
build | Build an image from a Dockerfile |
run | Run a command in a new container |
volume | Manage volumes |
stop | Stop one or more running containers |
commit | Create a new image from a container’s changes |
A complete list of commands available via the command “help”.
How to Use the Docker Container with JMeter
Now it’s time for a practical example: we will execute a performance test using JMeter not directly installed on the test machine, but rather on a Docker container.
The user interaction with JMeter will be performed in two manners:
- Passing JMeter arguments with the “
docker run
” command (e.g. which jmx script must be executed, script parameters, etc) - Then, fetching the result file (e.g. jtl and log file) using a shared folder on the test machine called Docker volume, that can be used to save result files after the container execution ends.
As already written, if the container modifies the file system, it does not persist after the container finishes. So to obtain JMeter results it’s necessary to set up an exchange folder with the ‘volume’ command.
A representation of the involved entities is visible in the picture below.
On the left you can see our test machine that hosts the JMeter containers and the Docker volume. The volume is used to provide a JMX script file to be executed, and to retrieve from the container the JTL result file and the LOG file on execution.
On the right, on the other side of the network, there is the application under test. For the scope of this paper, it’s not crucial to know details about the application under test (e.g. it might be a container too).
In this example, the container starts and as a first action it executes a JMeter application with arguments passed with the “docker run” command. When JMeter completes its execution, the container stops itself, leaving the JMeter result files in the Docker volume.
Here is the step by step procedure:
First, install Docker and its command line client.
Depending on your test machine, select the appropriate installation package (could be up 200 MB to download). When the installation is complete, there will be:
1. A Docker service running in background on your test machine (or on VirtualBox for Docker Toolbox)
2. The test machine shell (e.g. bash for Linux, cmd for Windows) that can process Docker commands.
Now, let’s build an image from a Dockerfile. (If you have an image you can run “docker run -t <image_name> <arguments>” and view the results in the volume folder).
In this example we will not use a standard image that is available on Docker Hub, but one that is customized for our needs. So, it’s necessary to build one from a description file called Dockerfile. Dockerfiles (like images) can be shared between different users.