Springboot mongo docker-compose fail to connect

My docker-compose.yml is as shown

version: '3'
services:
  backend-service:
    image: 'storio-360-service:v1.0'
    build: .
    container_name: storio-360-service
    ports:
      - 8090:8080
    depends_on:
      - db_mongo
    links:
      - db_mongo
  db_mongo:
    image: 'mongo'
    container_name: db_mongo
    ports:
      - 27018:27017
    volumes:
      - /home/bob/Bob/data:/data/db
    restart: always

My Dockerfile is

FROM openjdk:8u111-jdk-alpine
VOLUME /tmp
ADD /target/backend-service-1.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
CMD curl "db_mongo:27018"

Because of this set up, my repository in my spring has this code

@Repository
public class WatcherRepository {

    private MongoOperations mongoOps;

    @Autowired
    public WatcherRepository() {
        String myHost = "db_mongo";
        this.mongoOps = new MongoTemplate(new SimpleMongoDbFactory(new MongoClient(myHost), MongoConstant.DATABASE_NAME));
    }

    // Other code to access the mongo db
}

However, when i run docker-compose up –build,

I get the following when Spring boot is starting up,

02:24:55.871 [main] INFO  org.mongodb.driver.cluster - Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
storio-360-service    | 02:24:55.923 [cluster-ClusterId{value='5d3faa779470450001317225', description='null'}-localhost:27017] INFO  org.mongodb.driver.cluster - Exception in monitor thread while connecting to server localhost:27017
storio-360-service    | com.mongodb.MongoSocketOpenException: Exception opening socket
storio-360-service    |         at com.mongodb.connection.SocketStream.open(SocketStream.java:62)
storio-360-service    |         at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:126)
storio-360-service    |         at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:114)
storio-360-service    |         at java.lang.Thread.run(Thread.java:745)
storio-360-service    | Caused by: java.net.ConnectException: Connection refused (Connection refused)
storio-360-service    |         at java.net.PlainSocketImpl.socketConnect(Native Method)
storio-360-service    |         at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
storio-360-service    |         at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
storio-360-service    |         at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
storio-360-service    |         at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
storio-360-service    |         at java.net.Socket.connect(Socket.java:589)
storio-360-service    |         at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:59)
storio-360-service    |         at com.mongodb.connection.SocketStream.open(SocketStream.java:57)
storio-360-service    |         ... 3 common frames omitted
storio-360-service    | 02:24:56.060 [main] INFO  org.mongodb.driver.cluster - Cluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500

Then Spring boot will shown that it is waiting for calls as it sets up successfully.

02:34:39.274 [main] INFO  o.d.i.i.storio.service.Service - Started Service in 5.353 seconds (JVM running for 6.085)

However, when i make the api call which will call the mongodb, it shows me the error

Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]

I am new to Docker and it is clear that my springboot cannot access mongo. What am i doing wrong in my Dockerfile or docker-compose? thanks

Source: StackOverflow