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

Docker容器运行JMeter报错:jmeter.sh:111: ./jmeter: not found

Docker容器运行JMeter性能测试报错:jmeter.sh: 111: ./jmeter: not found

问题详情

执行Docker命令:

docker run --env-file enviormentVariables.txt esign_performance_testing:latest env

随后运行JMeter脚本命令时失败:

sh jmeter.sh ${RMI_HOST_DEF} -n -t ./Scripts/Test.jmx -l ./Results/Results_$timestamp.jtl -j ./Log/ScriptLogs_$timestamp.log -e -o ./Report/RunReport_$timestamp -JProfile=1

触发报错:

"jmeter.sh: 111: ./jmeter: not found"

相关文件内容

Dockerfile

FROM public.ecr.aws/docker/library/ubuntu:focal

ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=America/New_York

RUN apt-get update \
 && apt-get install wget unzip zip -y

RUN apt-get update && apt-get install -y gnupg2

# 配置Chrome PPA源
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list

# 更新源并安装Chrome
RUN apt-get update -y
RUN apt-get install -y google-chrome-stable
RUN echo "complete"

# 配置ChromeDriver环境变量
ENV CHROMEDRIVER_VERSION 2.19
ENV CHROMEDRIVER_DIR /chromedriver
RUN mkdir $CHROMEDRIVER_DIR

# 下载并安装ChromeDriver
RUN wget -q --continue -P $CHROMEDRIVER_DIR "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip"
RUN unzip $CHROMEDRIVER_DIR/chromedriver* -d $CHROMEDRIVER_DIR

# 将ChromeDriver加入PATH
ENV PATH $CHROMEDRIVER_DIR:$PATH

RUN apt-get update \
    && apt-get install -y apt-utils \
    build-essential \
    openjdk-8-jdk \
    zip \
    && apt-get clean
RUN apt-get update && apt-get install -y dos2unix

WORKDIR /app
COPY apache-jmeter-5.4 ./apache-jmeter-5.4

COPY docker-entrypoint.sh /entrypoint.sh
RUN ["chmod", "a+x", "/entrypoint.sh"]
RUN ["chmod", "a+x", "./apache-jmeter-5.4/bin/jmeter.sh"]  
RUN dos2unix /entrypoint.sh && apt-get --purge remove -y dos2unix && rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["/entrypoint.sh"]

Docker EntryPoint.sh

#!/bin/bash
set -e
echo Initializing the Performance Execution
echo "Script executed from: ${PWD}"
timestamp=$(date +%s)
echo Performance execution initialization complete
echo Performance execution Started Succesfully for timestamp $timestamp

cd ./apache-jmeter-5.4/bin/

for f in `find . -name '*.sh' -o -regex './s?bin/[^/]+' -o -regex './usr/sbin/[^/]+' -o -regex './usr/lib/[^/]+' `;do
( cd `dirname $f` && chmod a+x  `basename $f` )
done

ls -l *.sh

StartTime=$(date +"%d-%b-%y-%T")
StartUnixTime=$(date +"%s000")

echo Start time $StartTime
echo Start Unix time $StartUnixTime

RMI_HOST_DEF=-Djava.rmi.server.hostname=0.0.0.0

echo eSignLoadTest Execution Started
sh jmeter.sh ${RMI_HOST_DEF} -n -t ./Scripts/eSignLoadTest.jmx -l ./Results/Results_$timestamp.jtl -j ./Log/ScriptLogs_$timestamp.log -e -o ./Report/RunReport_$timestamp -JProfile=1

EndTime=$(date +"%d-%b-%y-%T")
EndUnixTime=$(date +"%s000")

echo Start time $EndTime
echo End Unix time $EndUnixTime

echo Zipping the HTML Dashboard
zip -P Smartsign+ -r ./Report/htmlReport$timestamp.zip ./Report/RunReport_$timestamp

echo eSignLoadTestEmail Execution Started Sending the zip file by email
sh jmeter.sh ${RMI_HOST_DEF} -n -t ./Scripts/eSignLoadTestEmail.jmx -JFolderTStamp=./Report/htmlReport$timestamp.zip -JStartTime=$StartTime -JEndTime=$EndTime  -JSUnixTime=$StartUnixTime -JEUnixTime=$EndUnixTime

echo Run completed Succesfully. Creating Run Reports For -  $timestamp
cd Log
echo Script Log Data for this execution -
cat ScriptLogs_$timestamp.log

mv SummaryReport.jtl SummaryReport_$timestamp.jtl
mv ViewResultsTree.jtl ViewResultsTree_$timestamp.jtl
cd ..
cd ..
echo Report files Created with suffix -  $timestamp
echo  Run completed Successfully

问题原因与解决方案

核心原因

报错本质是jmeter.sh脚本无法找到同目录下的jmeter可执行文件,常见诱因包括:

  • jmeter二进制文件缺少执行权限
  • 路径切换导致相对路径失效
  • 系统缺少JMeter运行依赖的底层库

具体修复步骤

  1. 补全JMeter可执行文件权限
    在Dockerfile中,除了给jmeter.sh加权限,还要给jmeter二进制文件添加执行权限,或者直接递归授权整个bin目录:

    # 方式1:单独授权jmeter文件
    RUN ["chmod", "a+x", "./apache-jmeter-5.4/bin/jmeter"]
    # 方式2:递归授权整个bin目录
    RUN chmod -R a+x ./apache-jmeter-5.4/bin/
    
  2. 修正路径引用问题
    Entrypoint中切换到apache-jmeter-5.4/bin/后,调用JMeter脚本时建议使用绝对路径,同时确保测试脚本、结果目录的路径正确:
    修改Entrypoint中的JMeter执行命令为:

    sh /app/apache-jmeter-5.4/bin/jmeter.sh ${RMI_HOST_DEF} -n -t /app/Scripts/eSignLoadTest.jmx -l /app/Results/Results_$timestamp.jtl -j /app/Log/ScriptLogs_$timestamp.log -e -o /app/Report/RunReport_$timestamp -JProfile=1
    

    同时在Dockerfile中提前创建必要目录:

    RUN mkdir -p /app/Scripts /app/Results /app/Log /app/Report
    
  3. 补充系统依赖库
    Ubuntu 20.04是64位系统,若JMeter二进制为32位版本,需安装32位兼容库:

    RUN apt-get update && apt-get install -y lib32z1 lib32ncurses5 lib32stdc++6
    
  4. 验证JMeter包完整性
    确保本地apache-jmeter-5.4目录完整,无bin/jmeter文件缺失。可在Dockerfile中添加验证步骤:

    RUN ls -la ./apache-jmeter-5.4/bin/
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 11:37:21