Using reactivemongo is a docker container

58 views
Skip to first unread message

amal...@gmail.com

unread,
Sep 15, 2020, 3:27:18 PM9/15/20
to ReactiveMongo - http://reactivemongo.org
I wonder if anyone has been able to build a docker image with play and reactivemongo. I have a play app which was working fine until i tried to containerise it. I have built my app image and i am able to deploy and run it except when i try to make a request from my containerised app to retrieve some data from my mongo database, i run into errors like these below. I am very new to using docker but so far, i have been able to do what i need to do. My question is this, do i need a mongo image to be able to use reactivemongo from my container? if so, can anyone please point me to some tutorial or some instructions on what i need to do. I usually use reactivemongo the usual way by setting my mongodb.uri in my `conf` file but i am guessing i need to do something extra since i am running in a container now.

my error when i try to connect to db. 
`ERROR r.core.actors.MongoDBSystem  [Supervisor-1/Connection-2] Fails to send a isMaster request to heroku-zjrm7hj4-shard-00-00.abo25.mongodb.net:27017 (channel #1eb8e84a)

java.nio.channels.ClosedChannelException: null

at reactivemongo.io.netty.channel.AbstractChannel$AbstractUnsafe.newClosedChannelException(AbstractChannel.java:957)

at reactivemongo.io.netty.channel.AbstractChannel$AbstractUnsafe.write(AbstractChannel.java:865)

at reactivemongo.io.netty.channel.DefaultChannelPipeline$HeadContext.write(DefaultChannelPipeline.java:1367)

at reactivemongo.io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:715)

at reactivemongo.io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:762)

at reactivemongo.io.netty.channel.AbstractChannelHandlerContext$WriteTask.run(AbstractChannelHandlerContext.java:1089)

at reactivemongo.io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)

at reactivemongo.io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)

at reactivemongo.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)

at reactivemongo.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)

at reactivemongo.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)

at reactivemongo.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)

at java.lang.Thread.run(Thread.java:748)

2020-09-15 14:17:02 ERROR r.core.actors.MongoDBSystem  [Supervisor-1/Connection-2] Fails to send a isMaster request to heroku-zjrm7hj4-shard-00-01.abo25.mongodb.net:27017 (channel #c58bf28d)

java.nio.channels.ClosedChannelException: null

at reactivemongo.io.netty.channel.AbstractChannel$AbstractUnsafe.newClosedChannelException(AbstractChannel.java:957)

at reactivemongo.io.netty.channel.AbstractChannel$AbstractUnsafe.write(AbstractChannel.java:865)

at reactivemongo.io.netty.channel.DefaultChannelPipeline$HeadContext.write(DefaultChannelPipeline.java:1367)

at reactivemongo.io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:715)

at reactivemongo.io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:762)

at reactivemongo.io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:788)

at reactivemongo.io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:756)

at reactivemongo.io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:765)

at reactivemongo.io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:788)

at reactivemongo.io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:756)

at reactivemongo.io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:765)

at reactivemongo.io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:788)

at reactivemongo.io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:756)

at reactivemongo.io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:765)

at reactivemongo.io.netty.channel.AbstractChannelHandlerContext$WriteTask.run(AbstractChannelHandlerContext.java:1089)

at reactivemongo.io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)

at reactivemongo.io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)

at reactivemongo.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:497)

at reactivemongo.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)

at reactivemongo.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)

at reactivemongo.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)

at java.lang.Thread.run(Thread.java:748)`

Cédric Chantepie

unread,
Sep 15, 2020, 6:15:00 PM9/15/20
to ReactiveMongo - http://reactivemongo.org
On Tuesday, 15 September 2020 at 21:27:18 UTC+2 amal...@gmail.com wrote:
I wonder if anyone has been able to build a docker image with play and reactivemongo. I have a play app which was working fine until i tried to containerise it. I have built my app image and i am able to deploy and run it except when i try to make a request from my containerised app to retrieve some data from my mongo database, i run into errors like these below. I am very new to using docker but so far, i have been able to do what i need to do. My question is this, do i need a mongo image to be able to use reactivemongo from my container?

It seems there are some misunderstanding about how Docker works.
The question there is, whatever is the containerization or virtualization mechanism, can my app env access to a service elsewhere through network.

I suggest you first read the official Docker documentation, that explains how network is working (and how Docker-Compose or Kubernetes are used to managed related containers with networks between). Not a question specific to neither ReactiveMongo nor to Play or MongoDB.
 
if so, can anyone please point me to some tutorial or some instructions on what i need to do. I usually use reactivemongo the usual way by setting my mongodb.uri in my `conf` file but i am guessing i need to do something extra since i am running in a container now.

It seems that your app tries to reach heroku, be cannot, either because you have networking issue (see prior remarks) or that the URI is not pointing to an actual MongoDB service.

Try to connect from the very same env a where the app is running to the very same DB with the same configuration to check what's wrong, e.g. using Mongo Shell.

amal...@gmail.com

unread,
Sep 16, 2020, 4:55:02 AM9/16/20
to ReactiveMongo - http://reactivemongo.org

Thanks a lot for the response and pointing me in the right direction.  The uri is pointing to a valid mongo service as i can connect normally to the db via shell and outside the container. I will read up on the docker documentation and post an update. 

amal...@gmail.com

unread,
Sep 16, 2020, 3:41:45 PM9/16/20
to ReactiveMongo - http://reactivemongo.org
Okay after much reading, i realise you misunderstood my question because i did not explain my issue correctly. The actual error i am having is this : "MongoError['No primary node is available! (Supervisor-1/Connection-2)']" when i try to connect to my db via the docker container. I am not running an image of mongo in another container hence i do not need docker-compose  to load multiple containers or swarm to communicate between two containers. The heroku you are seeing is actually the id of my mongo atlas db cluster (it was previously an mlab hosted on heroku db which got migrated to atlas hence the name). My db connection string works perfectly fine outside the container but from within the container, i get mongo error no primary node. I have whitelisted my local container IP but i am still getting the same error message. Again, i can connect with the same connection string outside the container from my app and via mongo shell. After containerization tho it throws the mentioned error.

Philip Whitehouse

unread,
Sep 16, 2020, 4:17:34 PM9/16/20
to reacti...@googlegroups.com
Are you actually exposing the MongoDB port correctly?

Internally we run MongoDB inside a container, pointing to an data image in another container and connect to it from a third container / the base OS (depending on environment) running Play with ReactiveMongoDB. All you need is to do ensure that the ports are exposed correctly.

This is definitely a docker networking problem not an app issue.

Best,

Philip Whitehouse

On 16 Sep 2020, at 20:41, amal...@gmail.com <amal...@gmail.com> wrote:

Okay after much reading, i realise you misunderstood my question because i did not explain my issue correctly. The actual error i am having is this : "MongoError['No primary node is available! (Supervisor-1/Connection-2)']" when i try to connect to my db via the docker container. I am not running an image of mongo in another container hence i do not need docker-compose  to load multiple containers or swarm to communicate between two containers. The heroku you are seeing is actually the id of my mongo atlas db cluster (it was previously an mlab hosted on heroku db which got migrated to atlas hence the name). My db connection string works perfectly fine outside the container but from within the container, i get mongo error no primary node. I have whitelisted my local container IP but i am still getting the same error message. Again, i can connect with the same connection string outside the container from my app and via mongo shell. After containerization tho it throws the mentioned error.
--
You received this message because you are subscribed to the Google Groups "ReactiveMongo - http://reactivemongo.org" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reactivemong...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/reactivemongo/ddc01dcb-1430-4e29-a64f-999c9d66142cn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages