【问题标题】:akka http: docker container is not connecting to the serverakka http:docker 容器未连接到服务器
【发布时间】:2020-03-05 08:43:23
【问题描述】:

我有一个 akka htpp 应用程序,这是我绑定它的方式

val host = "0.0.0.0"
    val port = 8080

    val bindingFuture = Http().bindAndHandle(MainRouter.routes, host, port)
log.info("Server online ")
    StdIn.readLine()
    bindingFuture
      .flatMap(_.unbind()) // trigger unbinding from the port
      .onComplete(_ => system.terminate()) // and shutdown when done

我正在使用sbt native packager 创建我的应用程序 docker 映像

我也加了

dockerExposedPorts:= Seq(8080)

在我的build.sbt

我正在运行我的容器 docker run -p 8080:8080 testapp:0.0.1 --bind 0.0.0.0

docker ps 显示

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
2e8e7ae35b10        testapp:0.0.1     "/opt/docker/bin/tes…"   13 minutes ago      Up 13 minutes       0.0.0.0:8080->8080/tcp   recursing_hellman

当我从浏览器中点击 0.0.0.0:8080 时,我得到了

This site can’t be reached The connection was reset.
Try:

Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_RESET 

或来自postman

Could not get any response
There was an error connecting to 0.0.0.0:8080/event-id?id=132

当 docker 容器在我的机器上运行时 数控-zv 0.0.0.0 8080 返回

Connection to 0.0.0.0 8080 port [tcp/http-alt] succeeded!

容器内

docker exec -it 2e8e7ae35b10 bash

我试过了

curl 'http://0.0.0.0:8080/health'
curl: (7) Failed to connect to 0.0.0.0 port 8080: Connection refused

我的应用在 docker 之外运行良好

【问题讨论】:

  • 您能检查一下应用程序内部是否有任何异常或错误消息吗?为此,您可以使用docker logs
  • 也不例外

标签: scala docker akka-http


【解决方案1】:

我认为问题是 docker 默认关闭标准输入,这可能会影响您的应用程序,因为它会提示用户输入 StdIn.readLine()。解决方案可以是run the container with the -i option to keep stdin open

如果有帮助请告诉我!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-14
    相关资源
    最近更新 更多