无法在docker中运行jmx文件

时间:2019-11-29 14:08:14

标签: docker jmx

使用cygwin从Windows计算机连接的服务器

在服务器中创建了一个docker文件

[root@serverhost uname]# touch Dockerfile

[root@serverhost uname]# vi Dockerfile

Dockerfile:

#1
FROM artifactory.xxx.net/java:8.212.0.1557388225_openjdk_74e62a71
#2
LABEL maintainer="xxx@domain.com"
# 3
ARG JMETER_VERSION="5.2"

# 4
ENV JMETER_HOME /opt/apache-jmeter-${JMETER_VERSION}
ENV JMETER_BIN  ${JMETER_HOME}/bin
ENV MIRROR_HOST http://mirrors.ocf.berkeley.edu/apache/jmeter
ENV JMETER_DOWNLOAD_URL ${MIRROR_HOST}/binaries/apache-jmeter-${JMETER_VERSION}.tgz
ENV JMETER_PLUGINS_DOWNLOAD_URL http://repo1.maven.org/maven2/kg/apc
ENV JMETER_PLUGINS_FOLDER ${JMETER_HOME}/lib/ext/

# 5
RUN    apk update \
        && apk upgrade \
        && apk add ca-certificates \
        && update-ca-certificates \
            && apk add --update openjdk8-jre tzdata curl unzip bash \
            && cp /usr/share/zoneinfo/Europe/Rome /etc/localtime \
            && echo "Europe/Rome" >  /etc/timezone \
        && rm -rf /var/cache/apk/* \
        && mkdir -p /tmp/dependencies  \
        && curl -L --silent ${JMETER_DOWNLOAD_URL} >  /tmp/dependencies/apache-jmeter-${JMETER_VERSION}.tgz  \
        && mkdir -p /opt  \
        && tar -xzf /tmp/dependencies/apache-jmeter-${JMETER_VERSION}.tgz -C /opt  \
        && rm -rf /tmp/dependencies

# 6
RUN curl -L --silent ${JMETER_PLUGINS_DOWNLOAD_URL}/jmeter-plugins-dummy/0.2/jmeter-plugins-dummy-0.2.jar -o ${JMETER_PLUGINS_FOLDER}/jmeter-plugins-dummy-0.2.jar
RUN curl -L --silent ${JMETER_PLUGINS_DOWNLOAD_URL}/jmeter-plugins-cmn-jmeter/0.5/jmeter-plugins-cmn-jmeter-0.5.jar -o ${JMETER_PLUGINS_FOLDER}/jmeter-plugins-cmn-jmeter-0.5.jar

# 7
ENV PATH $PATH:$JMETER_BIN

# 8
COPY launch.sh /

#9
WORKDIR ${JMETER_HOME}

#10
ENTRYPOINT ["/launch.sh"]

在创建docker的同一文件夹中创建了launch.sh文件

[root@serverhost uname]# touch launch.sh

[root@serverhost uname]# vi launch.sh

launch.sh文件

#!/bin/bash

set -e
freeMem=`awk '/MemFree/ { print int($2/1024) }' /proc/meminfo`
s=$(($freeMem/10*8))
x=$(($freeMem/10*8))
n=$(($freeMem/10*2))
export JVM_ARGS="-Xmn${n}m -Xms${s}m -Xmx${x}m"

echo "START Running Jmeter on `date`"
echo "JVM_ARGS=${JVM_ARGS}"
echo "jmeter args=$@"

# Keep entrypoint simple: we must pass the standard JMeter arguments
jmeter $@
echo "END Running Jmeter on `date`"

构建码头工人并对其进行标记

[root@serverhost uname]# docker build .

[root@serverhost uname]# docker tag 090847728937 jmautomation:1.0

从服务器退出并将我的本地jmx文件夹复制到服务器

uname@QINDW191 /cygdrive/c/jmeter/$ scp -r jmeterscript uname@serverhost:~/

[uname@serverhost~]$ ls -lrt

total 12

-rw-r--r--. 1 root   root   1678 Nov 26 10:29 Dockerfile

-rw-r--r--. 1 root   root    331 Nov 26 11:00 launch.sh

drwxrwx---. 2 uname uname 4096 Nov 28 09:17 jmeterscript

在docker中运行jmx文件,方法是将文件夹复制到docker mnt / jmeter文件夹并从那里运行jmx文件:

[root@serverhost uname]# docker run -v /home/uname/jmeterscript:/mnt/jmeter jmautomation:1.0 -n -Jenv=devint  -t /mnt/jmeter/api_regression.jmx -l /mnt/jmeter/result.xml

[root@serverhost uname]# docker run --volume "/home/uname/jmeterscript":/mnt/jmeter jmautomation:1.0 -n -Jenv=devint  -t /mnt/jmeter/api_regression.jmx -l /mnt/jmeter/result.xml

[root@serverhost uname]# docker run --volume "/home/uname/jmeterscript":/mnt/jmeter jmautomation:1.0 -n -Jenv="devint"  -t /mnt/jmeter/api_regression.jmx -l /mnt/jmeter/result.xml

[root@serverhost uname]# docker run --volume "/home/uname/jmeterscript":/mnt jmautomation:1.0 -n -Jenv=devint  -t /mnt/api_regression.jmx -l /mnt/result.xml

每次我遇到以下错误时,都尝试使用上述所有命令运行

docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"-n\": executable file not found in $PATH": unknown.
ERRO[0001] error waiting for container: context canceled

有人可以帮助我我所缺少的吗?

0 个答案:

没有答案