如何从docker文件获取环境变量

时间:2022-03-05 12:05:18

How can I get the environment variable from docker file for example I am adding a

如何从docker文件中获取环境变量,例如我正在添加一个

ENV URL_PATH="google.com"

in my dockerfile, so can I get the this URL_PATH in my Jmeter.jmx file with the help of User Defined Variable.

在我的dockerfile中,我可以在我的Jmeter中获得这个URL_PATH。在用户定义变量的帮助下的jmx文件。

On window its working fine with proper {__env(URL_PATH)}

在窗口上,它可以使用适当的{__env(URL_PATH)}

but on docker its not working. How can I solve this problem?

但在docker上就没用了。我该如何解决这个问题?

2 个解决方案

#1


2  

You can use the -e option to pass environment variables into the container when running it.

可以使用-e选项在运行容器时将环境变量传递到容器中。

docker run -e URL_PATH=google.com ...

Docs: https://docs.docker.com/engine/reference/run/#env-environment-variables

文档:https://docs.docker.com/engine/reference/run/ # env-environment-variables

#2


0  

As far as I can see __env() is a Custom JMeter Function therefore it is not available in vanilla JMeter so the options are in:

就我所见,__env()是一个自定义的JMeter函数,因此它在vanilla JMeter中是不可用的,所以选项是:

  1. Amend your Dockerfile to include downloading of http://repo1.maven.org/maven2/kg/apc/jmeter-plugins-functions/2.0/jmeter-plugins-functions-2.0.jar to "lib/ext". This way you will be able to use __env() function in Docker environment normally. See Make Use of Docker with JMeter - Learn How for example Docker configuration assuming using JMeter with Plugins.

    修改您的Dockerfile,包括下载http://repo1.maven.org/maven.org/maven2/kg/apc/jcm -plugins-function -2.0.jar到“lib/ext”。通过这种方式,您将能够在Docker环境中正常地使用__env()函数。参见使用JMeter中的Docker—了解如何使用带有插件的JMeter配置Docker。

  2. Switch to __groovy() function. Replace all the occurrences of {__env(URL_PATH)} with the following expression:

    切换到__groovy()函数。用以下表达式替换所有出现的{__env(URL_PATH)}:

    ${__groovy(System.getenv('URL_PATH'),)} 
    

#1


2  

You can use the -e option to pass environment variables into the container when running it.

可以使用-e选项在运行容器时将环境变量传递到容器中。

docker run -e URL_PATH=google.com ...

Docs: https://docs.docker.com/engine/reference/run/#env-environment-variables

文档:https://docs.docker.com/engine/reference/run/ # env-environment-variables

#2


0  

As far as I can see __env() is a Custom JMeter Function therefore it is not available in vanilla JMeter so the options are in:

就我所见,__env()是一个自定义的JMeter函数,因此它在vanilla JMeter中是不可用的,所以选项是:

  1. Amend your Dockerfile to include downloading of http://repo1.maven.org/maven2/kg/apc/jmeter-plugins-functions/2.0/jmeter-plugins-functions-2.0.jar to "lib/ext". This way you will be able to use __env() function in Docker environment normally. See Make Use of Docker with JMeter - Learn How for example Docker configuration assuming using JMeter with Plugins.

    修改您的Dockerfile,包括下载http://repo1.maven.org/maven.org/maven2/kg/apc/jcm -plugins-function -2.0.jar到“lib/ext”。通过这种方式,您将能够在Docker环境中正常地使用__env()函数。参见使用JMeter中的Docker—了解如何使用带有插件的JMeter配置Docker。

  2. Switch to __groovy() function. Replace all the occurrences of {__env(URL_PATH)} with the following expression:

    切换到__groovy()函数。用以下表达式替换所有出现的{__env(URL_PATH)}:

    ${__groovy(System.getenv('URL_PATH'),)}