How to control services start-up sequence in docker-compose.yml file?

Here is my docker-compose.yml file

version: ‘3’
services:
mongodb:
image: hedge-mongo:1.0
container_name: mongodb
ports:

  • “27017:27017”
    networks:
  • appNetwork
    service-A:
    image: service-A:1.0
    container_name: service-A
    ports:
  • “3030:3030”
    networks:
  • appNetwork
    depends_on:
  • mongodb
    service-B:
    image: service-B:1.0
    container_name: service-B
    ports:
  • “4200:4200”
    networks:
  • appNetwork
    service-C:
    image: service-C:1.0
    container_name: service-C
    ports:
  • “8082:8082”
    networks:
  • appNetwork
    networks:
    appNetwork:
    external: true

In above file service-A and service-C are trying to connect to MongoDB
Issue:
In above file service-A and service-C are getting connected to MongoDB before MongoDB is up
so, I want to run service-A and service-C after MongoDB is up completely
I tried adding depends-on for service-A and service-C

service-A:
image: service-A:1.0
container_name: service-A
ports:

  • “3030:3030”
    networks:
  • appNetwork
    depends_on:
  • mongodb

service-C:
image: service-C:1.0
container_name: service-C
ports:

  • “8082:8082”
    networks:
  • appNetwork
    depends_on:
  • mongodb

still, it did not work out sometimes it works sometimes it doesn’t so it’s not reliable.
I want to make sure my other services are up only after MongoDB is up.

Hi @shraddhaagarwal ,

This post was moved to a different board that fits your topic of discussion a bit better. This means you’ll get better engagement on your post, and it keeps our Community organized so users can more easily find information.

As you’ll notice, your Topic is now in the Project Development Help board. No action is needed on your part; you can continue the conversation as normal here.

Let me know if you have any other questions or if I can help with anything else.

Cheers!