You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Docker VOLUME命令解决容器停止后获取JMeter HTML报告的问题

How to Retrieve JMeter HTML Reports from a Stopped Docker Container Using Volumes

Got it, let's walk through this clearly—your current setup runs JMeter during image build (with RUN), but that's not ideal for two key reasons:

  1. The RUN command executes when you build the image, not when you run the container. So you're stuck with a static report from build time, not fresh results from each container run.
  2. Even if you fixed that to run JMeter when the container starts, once the container stops, all its internal files (including the report) get deleted unless you persist them with a volume.

Here are two straightforward ways to fix this, starting with the most flexible option:

This lets you directly save the report to a folder on your host machine without modifying your Dockerfile.

  1. First, create a directory on your host to store reports:

    mkdir -p ./jmeter-reports
    
  2. Run your container with the -v flag to mount this host directory to the exact path where JMeter outputs the report in the container. Make sure the right-hand path matches the -o argument in your JMeter command:

    docker run --rm -v $(pwd)/jmeter-reports:/path/to/container/bin/Result_Html your-jmeter-image-name
    
    • Replace /path/to/container/ with the actual working directory of JMeter in your container (e.g., if JMeter lives at /opt/apache-jmeter-5.6.3/, use /opt/apache-jmeter-5.6.3/bin/Result_Html).
    • The --rm flag cleans up the container automatically after it finishes running.

Once the container stops, check your host's ./jmeter-reports folder—your HTML report will be there!

Option 2: Define a Volume in Your Dockerfile

If you want to pre-configure the volume in your image (so you don't have to remember the -v flag every time), modify your Dockerfile like this:

  1. Add a VOLUME instruction to specify the report output directory (match the -o path from your JMeter command):

    VOLUME ["/jmeter/bin/Result_Html"]
    
  2. Replace the final RUN command with CMD—because RUN runs during build, but CMD runs when the container starts (so you get fresh results each time):

    CMD ["./bin/jmeter", "-n", "-t", "./bin/Get_Ping_Node_API.jmx", "-l", "./bin/result.jtl", "-e", "-o", "./bin/Result_Html"]
    
  3. Rebuild your image:

    docker build -t your-jmeter-image-name .
    

Now when you run the container, you can still specify a host directory to mount (same as Option 1):

docker run --rm -v $(pwd)/jmeter-reports:/jmeter/bin/Result_Html your-jmeter-image-name

If you don't specify a host directory, Docker will create an anonymous volume to store the report. You can find it with docker volume ls and inspect its host path with docker inspect <volume-name>, but this is less convenient than mounting a known directory.

Key Notes to Avoid Headaches

  • Path Matching: Double-check that the container path in your -v flag or VOLUME instruction exactly matches the -o path in your JMeter command. Mismatched paths mean no report gets saved.
  • Permissions: If you get "permission denied" errors, either:
    • Run the container with root user: add -u root to your docker run command.
    • Set open permissions on your host report directory: chmod 777 ./jmeter-reports (use cautiously in production).
  • Fresh Results: Using CMD instead of RUN ensures you generate a new report every time you run the container, not just once during image build.

内容的提问来源于stack exchange,提问作者Sumit Garg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:06:18