Docker – JMeter Integration

Suppose we have a Dockerfile customized for our JMeter, and we build the image with this command:

docker build -t jmeter <path to Dockerfile>
jmeter with docker explanation

During the build process, many network contents can be fetched, making the “docker build” command execution time a variable you should be aware of. What kinds of content are collected? At least one Docker Image to be used as the first building brick. After the contents type can vary, from a simple text file to archive package (e.g. zip, tar.gz, rpm, deb, etc). Afterwards, these files are “installed” on the image with specific commands (e.g. copy for text file, unzip for zip, tar for tar.gz, etc).

At the end of the build it is possible to see how a new image is “tagged” and available in the local cache.

Increase image
how can i run jmeter from a docker image

Now it’s possible to see the created image in the local cache with the command

running a jmeter script from a docker container

As visible in the picture above, there are two images in the local cache. One was just created by us and one downloaded because it was referenced during the build process.

Now it’s time to create a Docker volume to exchange files with the container. Use the command

docker volume create <volume name>

If we don’t want to provide more information, Docker chooses all the volume configuration details for us (e.g. real path on host machine). With the command

docker volume inspect <volume name>

it’s possible to retrieve where the volume is mapped on the test machine.

If the test machine is on Windows or you don’t want to create a stand alone volume, you can specify the volume directly with the container execution command line via arguments.

Now it’s time to execute the containers!

Bash

export timestamp=$(date +%Y%m%d_%H%M%S) && \
export volume_path=<where files are on host> && \
export jmeter_path=/mnt/jmeter && \
docker run \
  --volume “${volume_path}”:${jmeter_path} \
  jmeter \
  -n <any sequence of jmeter args> \
  -t ${jmeter_path}/<jmx_script> \
  -l ${jmeter_path}/tmp/result_${timestamp}.jtl \
  -j ${jmeter_path}/tmp/jmeter_${timestamp}.log

The above command line shows:

  • setup of environment variables working folder for host/container
  • setup of environment variables for a timestamp label to be used in the result file
  • “docker run” command with volume mapping definition on “jmeter” image
  • starting from “-n” there are arguments passed directly to the JMeter application on the container (e.g. no gui mode, jmx script and result file name)
  • with “-t ${jmeter_path}/<jmx_script>” we are defining the jmx script to be executed. From the container point of view, the script is into folder “/mnt/jmeter” (see previous export command). In reality, the jmx script is external to container and provided via  the Docker volume.
Increase image
uding jmeter scripts with docker

After completing the container execution, the control returns to the user and the JMeter result files are available under the tmp folder in the <volume_path> and can be used as a normal JMeter result file.

Increase image
run your jmx file from a docker image

Pages: 1 2 3