0 votes
in Docker by

How will you ensure that a container 1 runs before container 2 while using docker compose?

1 Answer

0 votes
by

Docker-compose does not wait for any container to be “ready” before going ahead with the next containers. In order to achieve the order of execution, we can use:

The “depends_on” which got added in version 2 of docker-compose can be used as shown in a sample docker-compose.yml file below:

version: "2.4"

services:

 backend:

   build: .

   depends_on:

     - db

 db:

   image: postgres

The introduction of service dependencies has various causes and effects:

The docker-compose up command starts and runs the services in the dependency order specified. For the above example, the DB container is started before the backend.

docker-compose up SERVICE_NAME by default includes the dependencies associated with the service. In the given example, running docker-compose up backend creates and starts DB (dependency of backend).

...