com.mongodb.MongoSocketOpenException: when connecting to mongodb docker container

I have an sbt project which has mongodb code i am making a custom image of this sbt project and using mongodb:2.6.11 public docker image https://hub.docker.com/_/mongo

here is the docker file of my sbt project

FROM hseeberger/scala-sbt:11.0.2_2.12.8_1.2.8 as stripecommon

MAINTAINER sara <[email protected]>

WORKDIR /myproject

ADD myprojectcode .

CMD ["sbt","reload","clean","compile","run"] 

and here is the dockerfile of the mongodb image mongodb:2.6.11 https://github.com/ky13R/mongo-2.6.11-docker-image/blob/master/Dockerfile

here is how i am running my containers

docker create network mynetwork

to start mongodb container

docker run -p 27017 --network mynetwork mongo:2.6.11

to start my project container

docker run --network mynetwork myproject:v1

and my project is unable to connect to the mongodb server here is the exception log

com.mongodb.MongoSocketOpenException: Exception opening socket
    at com.mongodb.connection.SocketStream.open(SocketStream.java:63)
    at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
    at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:128)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
    at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
    at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
    at java.base/java.net.Socket.connect(Socket.java:591)
    at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)
    at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
    ... 3 common frames omitted

i have followed this tutorial to connect to mongodb server
https://dzone.com/articles/using-docker-to-shove-an-existing-application-into
what i am doing wrong here?

the code for connecting to mongo server is

private val DATABASE:String   = config.getString("db.dbname")
  private val SERVER:ServerAddress = {
      val hostName=config.getString("db.hostname")
      val port=config.getString("db.port").toInt
    new ServerAddress(hostName,port)
      } 
  val connectionMongo = MongoClient(SERVER)
  log.debug("mongo connection created "+connectionMongo)
  def collectionMongo(name:String) = connectionMongo(DATABASE)(name)
  log.debug("getting collection from mongodb")
} 

and here is the config file

db.url="mongodb://Localhost:27017"
db.hostname="Localhost"
db.dbname=testdb
db.port=27017

Source: StackOverflow