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

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

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.DefaultServerMonitor$
    at java.base/
Caused by: Connection refused (Connection refused)
    at java.base/ Method)
    at java.base/
    at java.base/
    at java.base/
    at java.base/
    at java.base/
    at com.mongodb.connection.SocketStreamHelper.initialize(
    ... 3 common frames omitted

i have followed this tutorial to connect to mongodb server
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


Source: StackOverflow