1

我在设置正确配置以能够访问部署到 docker 容器中的 akka 应用程序时遇到一些困惑。虽然我正在运行一个 virtualbox ubuntu VM,但我首先希望能够在 VM 主机上转发端口之前从该 VM 访问容器。应用程序.conf:

akka {
  actor {
    provider = remote
  }
  remote {
    enabled-transports = ["akka.remote.netty.tcp"]
    netty.tcp {
      hostname = ${?HOSTNAME}       # what should it be? 0.0.0.0 or the assigned docker one like 172.17.0.x but unknown in advance
      port = ${?PORT}               # 800

      bind-hostname = ${?BIND_HOSTNAME} # 127.0.0.1 ?
      bind-port = ${?BIND_PORT}         # 800 ? xxxx ?

      # 30Mb max msg
      message-frame-size =  30000000b
      send-buffer-size =  30000000
      receive-buffer-size =  30000000b
      maximum-frame-size = 30000000b
    }
  }
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  loglevel = "DEBUG"
  logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
}

我的 docker 文件根据日志正确构建和运行应用程序:

FROM openjdk:8u151

    # Env variables
    ENV SCALA_VERSION 2.12.4
    ENV SBT_VERSION 1.1.1

    # Scala expects this file
    RUN touch /usr/lib/jvm/java-8-openjdk-amd64/release

    # Install Scala
    # Piping curl directly in tar
    RUN \
      curl -fsL https://downloads.typesafe.com/scala/$SCALA_VERSION/scala-$SCALA_VERSION.tgz | tar xfz - -C /root/ && \
      echo >> /root/.bashrc && \
      echo "export PATH=~/scala-$SCALA_VERSION/bin:$PATH" >> /root/.bashrc

    # Mk app dir
    RUN mkdir /alor

    # Define working directory
    WORKDIR /alor

    # Add target packaged app
    COPY target/universal/stage/ /alor/

    # Expose ports
    EXPOSE 800
    EXPOSE 5150

    # Launch the app
    CMD ./bin/alor

运行映像后,我在检查容器后尝试访问地址 172.17.0.x:800 但没有在容器控制台上记录任何内容。

4

1 回答 1

2

找到了我自己的解决方案,不知道它是否归结为绑定配置中的 akka 问题,或者原始 openjdk 图像没有本地网络的内部绑定,因为我尝试了不同的方法,例如bind-hostname = 127.0.0.1 bind-port=xxx但设置:

  hostname = 172.17.0.2   
  port = 800

  bind-hostname = 0.0.0.0
  bind-port = ""         

使 akka 系统可以从外部世界访问172.17.0.2:800。docker容器的ip也可以使用内网,不用猜测

于 2018-02-28T09:34:36.997 回答