Configure Akka.Net Remoting such that process inside (windows) docker container can talk to process on local host

Viewed 218

I have 2 Akka.Net processes that talk to each other via remoting.

Process 1 has the following app.hocon:

 akka{
 actor{
    provider = remote
 }

 remote{
    dot-netty.tcp.port = 1111
 }
}

Process 2 has the following app.hocon:

 akka{
 actor{
    provider = remote
 }

 remote{
    dot-netty.tcp.port = 2222
    dot-netty.tcp.hostname = "localhost"

 }
}

Note that the configs are very simple since both processes are on localhost.

Process 1 connects to Process 2 actors with commands like:

Process1ActorSystem.ActorSelection($"akka.tcp://Process2ActorSystem@localhost:2222/user/someActor");

Process 2, upon receiving a "SubscribeMessage" from Process 1, "Tells" data back to Process 1 (Context.Sender.Tell).

When both processes are run on same machine, they talk to each other just fine.

Process 2 when run inside a docker container seems to work fine in and of itself (excepting the Process 1-<->Process 2 communication).

However, I'm not at all clear what I need to put into the process 2 dockerfile, the docker run command, the process 1 hocon and the process 2 hocon so that Process 1 can still talk when Process 2 is running a a container.

I guess that I need to get the right combination of some subset of these values in both Process 1 hocon and Process 2 hocon, plus get the right EXPOSE statements in my dockerfile and/or the right port mappings in my docker run.

Process 1 hocon:    
   "port" : "1111".     
    #"hostname": "???? or omit",
    #"bind-hostname": "???? or omit",
    #"bind-port": "???? or omit",
    #"public-hostname": "???? or omit",
    #"public-port": "???? or omit",

Process 2 hocon:    
    "port" : "2222".     
    #"hostname": "???? or omit",
    #"bind-hostname": "???? or omit",
    #"bind-port": "???? or omit",
    #"public-hostname": "???? or omit",
    #"public-port": "???? or omit",

Dockerfile:
    EXPOSE 2222 #or omit?

Docker run:
  docker run -p 2222:2222 mycontainer

Any guidance much appreciated.

Update:

I've increased debug log level and I now see this from Process 2 when Process 1 tries to send a message. Note: the IP of the container is 172.22.87.66 and this is where Process 1 is addressing. BUT it seems that because Process 2 has hostname of 0.0.0.0 it receives the message, but rejects it.

Probably I could fix this by changing the Process 2 hocon to hostname 172.22.87.66 BUT that IP address changes every time I run the container, so that cant' be the whole solution.

[ERROR][3/7/2020 10:24:03 AM][Thread 0010][akka.tcp://ActorSystemRemote2@0.0.0.0:8222/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2FActorSystemRemote1%40host.docker.internal%3A8111-1/endpointWriter] Dropping message [Akka.Actor.ActorSelectionMessage] for non-local recipient [[akka.tcp://ActorSystemRemote2@172.22.87.66:8222/]] arriving at [akka.tcp://ActorSystemRemote2@172.22.87.66:8222] inbound addresses [akka.tcp://ActorSystemRemote2@0.0.0.0:8222]

Update 2

OK so now I do have the two processes communicating, but it isn't a viable long term setup. I attached to the running container and did an ipconfig to get its IP. I guess I could have used

docker network inspect nat 

or similar too.

Having got the IP I editing the app.hocon INSIDE the running container and restarted the Process2 executable.

Then from Process 1 I addressed Process2 using that IP.

Also Process 1 is using public-hostname of host.docker.internal which I believe is necessary for Process 2 to be able to address it.

akka{
 actor{
    provider = remote
 }

 remote{
    dot-netty.tcp.port = 8111,
    dot-netty.tcp.hostname = 172.22.80.1
    dot-netty.tcp.public-hostname=host.docker.internal
 }
}

enter image description here

1 Answers

Turned out to be very simple.

akka{
 actor{
    provider = remote
 }

 remote{
    dot-netty.tcp.port = 1111
 }
}
Process 2 has the following app.hocon:

 akka{
 actor{
    provider = remote
 }

 remote{
    dot-netty.tcp.port = 2222
    dot-netty.tcp.public-hostname = "localhost" //this was the key addition

 }
}

docker run -p 2222:2222 myimage

and the dockerfile had EXPOSE 2222 in it.

Related