in Technology by
How to check 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).
  • Finally, the command docker-compose stop also stops the services in the order of the dependency specified. For the given example, the backend service is stopped before the DB service.

Related questions

0 votes
    Now that links are deprecated in docker-compose.yml (and were able to use the new networking feature to ... docker-compose.yml? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Can we use JSON instead of YAML while developing docker-compose file in Docker?...
asked Jun 21, 2021 in Technology by JackTerrance
0 votes
    My docker-compose file has some running docker files to create my containers. I don't want the docker files ... docker-compose syntax? Select the correct answer from above options...
asked Jan 25, 2022 in Education by JackTerrance
0 votes
    What are the purposes of up, run, and start commands of docker compose?...
asked Jun 20, 2021 in Technology by JackTerrance
0 votes
    What is Docker Compose?...
asked Jun 18, 2021 in Technology by JackTerrance
0 votes
    I have a dump.sql file that I would like to load with docker-compose. docker-compose.yml: services: postgres: ... how to do this? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a dump.sql file that I would like to load with docker-compose. docker-compose.yml: services: postgres: ... how to do this? Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    I'm looking for a way to configure Nginx to access hosted services through a subdomain of my server. Those services ... me with this? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    1. _______________is a master control program that runs a computer. (a) An operating (b) A compiler (c) An interpreter Select the correct answer from above options...
asked Dec 2, 2021 in Education by JackTerrance
0 votes
    I'm trying to teach myself about Docker and using the docker-compose.yml to play around with images and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    I have tried to build a docker image based on mono to serve a docfx documentation. Here is my ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 15, 2022 in Education by JackTerrance
0 votes
    So I have a Nginx running inside a docker container, I have a mysql running on the host system, I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    This is my Xml document(small snippt). Table 11: Tanjavur NREGS activities CHAPTER IV: Findings and analysis ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
...