首页 > 解决方案 > 在 docker 中运行 K6 脚本时出现 ModuleSpecifier 错误

问题描述

我对docker的了解有限。但这就是我所做的。我安装了docker桌面。为 influxdb 1.8 和 grafana 和 loadimpact/k6 提取图像。为运行良好的 influxdb 和 grafana 创建了容器。

http://localhost:3000/ -> 工作 http://localhost:8086/ -> 找不到 404 页面

我想在 docker 中运行我的 k6 脚本,将结果保存在 influxdb 中,然后使用 grafana 根据 influxdb 中的数据创建自定义仪表板。

当我从 K6 脚本所在文件夹的命令提示符下发出以下命令时:

docker run -v /k6 -i loadimpact/k6 run --out influxdb=http://localhost:8086/myk6db - <K6-script.js

我收到以下错误。

time="2021-10-16T10:09:58Z" level=error msg="The moduleSpecifier \"./libs/shim/core.js\" couldn't be found on local disk. Make sure that you've specified the right path to the file. If you're running k6 using the Docker image make sure you have mounted the local directory (-v /local/path/:/inside/docker/path) containing your script and modules so that they're accessible by k6 from inside of the container, see https://k6.io/docs/using-k6/modules#using-local-modules-with-docker.\n\tat reflect.methodValueCall (native)\n\tat file:///-:205:34(24)\n" hint="script exception"

该文件夹是 K6-script.js 所在的文件夹,另外两个文件夹是 K6 和库,它们是在 K6-script.js 中导入的。

然后我参考了 [https://k6.io/docs/using-k6/modules/#local-filesystem-modules][1] 并给出了以下命令

docker run -v //c/loadtesting:/src -i loadimpact/k6 run --out influxdb=http://localhost:8086/myk6db K6-script.js

这给了我以下错误。

level=error msg="The moduleSpecifier \"K6-script.js\" couldn't be found on local disk. Make sure that you've specified the right path to the file. If you're running k6 using the Docker image make sure you have mounted the local directory (-v /local/path/:/inside/docker/path) containing your script and modules so that they're accessible by k6 from inside of the container, see https://k6.io/docs/using-k6/modules#using-local-modules-with-docker. Additionally it was tried to be loaded as remote module by prepending \"https://\" to it, which also didn't work. Remote resolution error: \"Get \"https://K6-script.js\": dial tcp: lookup K6-script.js on 192.168.65.5:53: no such host\""

如何解决此错误并使用 influxdb 在 docker 中运行 K6 脚本?

标签: influxdbk6

解决方案


当我给出以下命令时,经过多次试验和错误,测试运行了。它无法连接到 InfluxDB 数据库,但这是我需要解决的另一个问题。但除此之外,测试运行。

docker run -v //c/loadtesting:/src -i loadimpact/k6 run --out influxdb=http://localhost:8086/myk6db /src/K6-script.js

我认为它需要容器内的脚本路径来运行脚本。


推荐阅读