Docker Community Forums

Share and learn in the Docker community.

Docker compose to start container Y once start up script from container X are executed completely

docker

(Mansing) #1

I am using docker-compose to spin up two containers as shown in below example. DB image has start up script which takes around 5 mins to get it’s execution completed.

Is there any way to start ‘web’ container once the start up script execution is finished from ‘db’ container?

services:
  web:
    image: webapp
    depends_on:
    - db
  db:
    image: db

Or lets say I have just one container and want to only start that container when the execution of start up script is finished,

I have referred https://docs.docker.com/compose/startup-order/ this one.


(Siju Oommen George) #2

in your ‘web’ container put a startup script which looks for the availability of the DB and brings your application up only once the DB is fully up. Let this startup script be your entry point. In the script you could sleep for a few seconds before trying to re connect to DB.