Figuring out Docker and Akka clustering with 2.4-SNAPSHOT (bind-hostname, bind-port)

785 views
Skip to first unread message

tigerfoot

unread,
Dec 29, 2014, 3:03:33 PM12/29/14
to akka...@googlegroups.com
Hello,

I'm trying to figure out how to get 2.4-SNAPSHOT going with Docker such that 1) I can access akka+http outside the running Docker container (i.e. from the host), and 2) I can enable clustering/discovery.  

I see from discussion threads and docs that the new bind-hostname and bind-port are designed to do this, but I haven't been able to come up with the right recipe to use them yet.

My code passes these arguments when Docker starts up:
   - IP address of host machine
   - port for Akka on host
   - http port

Like this:

docker run -i -t -p 9100:9100 -p 9101:9101 localhost:5000/root:1.0.0 --seed --name kernel --hostIP 172.16.240.78 --hostPort 9100 --httpPort 9101 --roles seed

(where 172.16.240.78 is the IP of my host running Docker)

Here's my application.conf.  

akka {
loglevel = "ERROR"
stdout-loglevel = "ERROR"
event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
log-dead-letters = 1
log-dead-letters-during-shutdown = off

actor {
provider = "akka.cluster.ClusterActorRefProvider"
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
# Outside Docker addr
bind-hostname  = ${server.ip}   # hostIP param
bind-port      = ${server.port} # hostPort param

# Inside Docker addr
port           = 0
}
}
cluster {
auto-down = on
log-info = off
# seed-nodes and roles set at runtime and added to config
}
}

I'm not sure I'm using these hostname/port, bind-hostname, bind-port correctly.  I've tried a few different permutations, which either fail to launch (w/messages saying it can't bind to an address) or it runs but I can't hit it outside my Docker container.
I need Akka to be able to discover its cluster nodes and be accessible on the given IP addr/port.

I have a trivial project set up here to show the approach:  https://github.com/gzoller/docker-exp/tree/akk2

I'm hoping I'm missing something simple in my config...

Any ideas?

Thanks!
Greg

tigerfoot

unread,
Dec 31, 2014, 12:37:45 PM12/31/14
to akka...@googlegroups.com
Think I've got it!  Here's the recipe for application.conf I got working to make Akka clustering work w/Docker:

akka {
loglevel = "ERROR"
stdout-loglevel = "ERROR"
loggers = ["akka.event.slf4j.Slf4jLogger"]
actor {
provider = akka.cluster.ClusterActorRefProvider
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
# Outside Docker
bind-hostname = ${dkr.local}

# Inside Docker addr
hostname = ${dkr.hostname}
port     = ${dkr.port}
}
}
cluster {
auto-down = on
log-info = off
}
}

Key Points:

1) seed-nodes (and roles FWIW) are set by my program but could be added to the cluster section here.  I happen to pass them into Docker via a parameter.  The IPs of the seeds are host IPs not the Docker-internal IPs (which I basically don't care about).

2) dkr.hostname/dkr.port are passed into Docker via parameters.  This is the *host* IP/port you want to run on (i.e. Docker-external IP addr).  Although I don't happen to care, I believe this also runs Akka on the same port inside Docker.  It might be an issue if you are running lots of things in your Docker container using ports, but I'm just running Akka, so I'm not picky.

3) dkr.local is set by my program (not passed in) and is just the Docker-internal IP address (retrieved by java.net.InetAddress.getLocalHost().getHostAddress()).

Took a little doing to get this right but it works.  This new binding functionality is a fantastic addition to Akka, as Docker is really a DevOps darling.  Looking forward to full 2.4 release!

Patrik Nordwall

unread,
Jan 5, 2015, 9:27:53 AM1/5/15
to akka...@googlegroups.com
Thanks for sharing!

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--

Patrik Nordwall
Typesafe Reactive apps on the JVM
Twitter: @patriknw

Reply all
Reply to author
Forward
0 new messages