【问题标题】:Connecting from gatling simulation inside Docker to localhost从 Docker 内的 gatling 模拟连接到 localhost
【发布时间】:2020-09-23 07:07:17
【问题描述】:

我正在尝试使用 MacOS 在 Docker 中使用 Gatling 测试我的 localhost 服务。

我使用以下方式运行 Docker:

  docker run -it -d --rm \
    --network="host" \
    -v $(PWD)/conf:/opt/gatling/conf \
    -v $(PWD)/user-files:/opt/gatling/user-files \
    -v $(PWD)/results:/opt/gatling/results \
    --name $CONTAINER_NAME $IMAGE_NAME

Afaik 使用 '--host' 可以从 Docker 内部使用主机网络。

我的服务在 9000 端口上运行,所以我在 Gatling 中的基本 url,所以我这样定义它:

  private val baseUrl = "http://127.0.0.1:9000"
  private val httpProtocol = http
    .baseUrl(baseUrl)

虽然我不断得到:

AbstractChannel$AnnotatedConnectException: Connection refused: /127.0.0.1:9000

我的配置有问题,还是 Gatling 限制有问题?

【问题讨论】:

  • 您使用的是哪个操作系统? Mac 还是 Windows?
  • 我用的是macOS,我会把它添加到问题中

标签: docker localhost gatling connection-refused


【解决方案1】:

将主机地址从http://127.0.0.1 更改为host.docker.internal,它应该可以工作。

本质上,host.docker.internal 将返回我们 docker 主机的 IP。但是这个特性只存在于 Docker for Mac OSX 和 Docker for Windows 中。您可以在此处阅读有关此功能的更多信息:

https://docs.docker.com/docker-for-mac/networking/

https://docs.docker.com/docker-for-windows/networking/.

【讨论】:

  • 谢谢,我能够连接到该服务。我想使用 linux 我必须显式传递本地 IP 才能达到相同的结果?
  • 您能接受答案并关闭问题吗?
猜你喜欢
  • 1970-01-01
  • 2012-01-08
  • 2016-05-28
  • 2017-08-11
  • 2019-03-08
  • 2017-07-25
  • 1970-01-01
相关资源
最近更新 更多