akka node in docker explicitly disassociated

I’m using akka 2.4-M2 in my project. And I want to deploy my projects with docker. However, when I’m using boot2docker to test the two nodes, there occurs a problem. My node cannot connect to seed-node.

The configuration in build.sbt is as below:

  • Akka and Docker on Marathon
  • Docker Akka-Http application endpoint not reachable
  • How can I maximize throughput in Docker and Akka HTTP?
  • What's a workable way setup an Akka cluster in a multi-node Docker environment?
  • Error using akka remoting with artery over docker instances
  • Akka 2.5 Distributed Data on Docker + Alpine Linux
  • lazy val `topGatewayFrontend` = (project in file("topGatewayFrontend"))
      .enablePlugins(PlayScala)
      .enablePlugins(DockerPlugin)
      .settings(
        name := "topGatewayFrontend",
        libraryDependencies ++= (Dependencies.topGatewayFrontend ++ Seq(cache,     ws)),
        dockerExposedPorts := Seq(9000)
      )
    
    lazy val `topGatewayBackend` = (project in file("topGatewayBackend"))
      .enablePlugins(JavaAppPackaging)
      .enablePlugins(DockerPlugin)
      .enablePlugins(UniversalPlugin)
      .settings(
        name := "topGatewayBackend",
        javaOptions in run ++= Seq(
          "-Djava.library.path=./sigar",
          "-Xms128m", "-Xmx512m"),
        // this enables custom javaOptions
        fork in run := true,
        libraryDependencies ++= Dependencies.topGatewayBackend ++ Seq(ws),
        dockerExposedPorts := Seq(9527)
      ).dependsOn(auditApi).aggregate(auditApi)
    

    Remote configeration in topGatewayFrontend is:

    akka{
      remote {
        log-sent-messages = on
        log-received-messages = on
        netty.tcp {
          hostname = ${?HOSTNAME}
          port = 9527                   # external (logical) port
          bind-hostname = 0.0.0.0
          bind-port = 0
        }
      }
      cluster {
        seed-nodes = ["akka.tcp://application@"${?HOSTNAME}":9527"]
        roles = [topGatewayBackend]
      }
    }
    

    In topGatewayBackend is :

    akka{
      remote {
        log-sent-messages = on
        log-received-messages = on
        netty.tcp {
          hostname = ${?HOSTNAME}
          port = 0              # external (logical) port
          bind-hostname = 0.0.0.0
          bind-port = 0
        }
      }
      cluster {
        seed-nodes = ["akka.tcp://application@"${?HOSTNAME}":9527"]
        roles = [topGatewayFrontend]
      }
    }
    

    And I got the log as below:

    In backend:

    [INFO] [07/12/2015 03:13:37.568] [application-akka.actor.default-dispatcher-16] [akka.cluster.Cluster(akka://application)] Cluster Node [akka.tcp://application@192.168.59.103:9527] - Metrics collection has started successfully
    [INFO] [07/12/2015 03:13:38.107] [application-akka.actor.default-dispatcher-16] [akka.cluster.Cluster(akka://application)] Cluster Node [akka.tcp://application@192.168.59.103:9527] - Leader is moving node [akka.tcp://application@192.168.59.103:9527] to [Up]
    [INFO] [07/12/2015 03:13:38.112] [application-akka.actor.default-dispatcher-4] [akka.tcp://application@192.168.59.103:9527/user/cluster-monitor] Member up akka.tcp://application@192.168.59.103:9527 with roles Set(topGatewayBackend)
    

    In frontend:

    [INFO] [07/12/2015 03:13:47.558] [main] [akka.remote.Remoting] Starting remoting
    [INFO] [07/12/2015 03:13:47.842] [main] [akka.remote.Remoting] Remoting started; listening on addresses :[akka.tcp://application@192.168.59.103:34354]
    [INFO] [07/12/2015 03:13:47.883] [main] [akka.cluster.Cluster(akka://application)] Cluster Node [akka.tcp://application@192.168.59.103:34354] - Starting up...
    [INFO] [07/12/2015 03:13:48.057] [main] [akka.cluster.Cluster(akka://application)] Cluster Node [akka.tcp://application@192.168.59.103:34354] - Registered cluster JMX MBean [akka:type=Cluster]
    [INFO] [07/12/2015 03:13:48.058] [main] [akka.cluster.Cluster(akka://application)] Cluster Node [akka.tcp://application@192.168.59.103:34354] - Started up successfully
    [INFO] [07/12/2015 03:13:48.251] [application-akka.actor.default-dispatcher-17] [akka.cluster.Cluster(akka://application)] Cluster Node [akka.tcp://application@192.168.59.103:34354] - Metrics collection has started successfully
    [WARN] [07/12/2015 03:13:48.509] [application-akka.remote.default-remote-dispatcher-5] [akka.tcp://application@192.168.59.103:34354/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2Fapplication%40192.168.59.103%3A9527-0] Association with remote system [akka.tcp://application@192.168.59.103:9527] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://application@192.168.59.103:9527]] Caused by: [The remote system explicitly disassociated (reason unknown).]
    

    Problem is that [Association failed with [akka.tcp://application@192.168.59.103:9527]] Caused by: [The remote system explicitly disassociated (reason unknown).]

    docker run command is:
    docker run -e HOSTNAME=192.168.59.103 -p 9527:9527 docker.fenxibao.com/topgatewaybackend:1.0-SNAPSHOT and docker run -p 9000:9000 -e HOSTNAME=192.168.59.103 docker.fenxibao.com/topgatewayfrontend:1.0-SNAPSHOT

    I’m wondering what I can do to make the frontend associate successfully with backend.

    Thanks in advance for your patient answers.

  • Docker, dockercloud and Cron
  • Build a docker image from vagrant
  • Mounting a dir in docker does not work when dir is linked with symlink?
  • New to React and trying to compile an APK but failing
  • Docker: limit VPN to single container
  • DocumentDB in Docker - “The authorization token is not valid at the current time.”
  • One Solution collect form web for “akka node in docker explicitly disassociated”

    Check this for how to run akka cluster within docker: http://blog.michaelhamrah.com/2014/06/akka-clustering-with-sbt-docker-and-sbt-native-packager/

    A short answer is that akka cluster requires the address to be consistent to both internal and external. So when you start your akka application within docker, you need to work with the internal ip address that is dynamically created for your container.

    You need to have a startup script like this:

    #!/bin/bash
    
    CLUSTER_IP=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1 }'` $@     
    

    Put it into your docker container, and use CLUSTER_IP environment variable in your akka config for its cluster host address.

    UPDATE:
    In docker version 1.10+, because of the new network feature added, there’s no need to have a startup script. You can just use the name of the container as reference and docker fix the address for you.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.