Mahyar
Mahyar

Reputation: 1121

Spinning up container after specific container is up and running

pretty new in docker-compose (and docker in general) here, I have a docker compose file which looks like this:

version: '3.5'

services:
   db:
      image: seeded-postgres_location
      ports:
      - 5432

   serv1:
      image: service1_location

   serv2:
      image: service2_location

here the seeded postgres is a container based on postgres, with some data initialized in it.

service1 needs the seeded-postgres container to be up and running before it starts since it runs some migrations and uses the data in postgres.

so my question is do these services/container spin-up sequentially - in the order listed by docker-compose ?

I want to make sure the db container spin up first, and after it's up and ready, service1 and service2 are spinning up.

Is there also a way to check if any error has been thrown by any of these containers - from docker-compose perspective?

Upvotes: 0

Views: 67

Answers (1)

keydon
keydon

Reputation: 729

You can use depends_on to express dependencies between services. but sadly neither this nor a healthcheck guarantee that a dependency is fully up and running before the actual service starts.

This can only be achieved by a custom logic (implemented in the container), that checks and waits until the dependencies are available. i.e. in an entrypoint script checking if the postgres port is accessible.

Upvotes: 1

Related Questions