Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
How to make a service wait for another to be ready?

I am using flyway with a mysql db. I am using them as services in a docker-compose and then using this in testcontainer's DockerComposeEnvironment. The problem is that even though I have added the depends_on key in 'flyway' service for the MySQL 'db', testcontainer starts flyway first and this results in the migrations not being applied.

I want to know if there is a method by which we can make flyway container run only when the db container is ready?

I am using this piece of code to initialize my test docker-compose environment (test_mysql and flyway_c are the names of the containers of the services):

const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
        .withWaitStrategy('test_mysql', Wait.forLogMessage(`ready for connections. Bind-address: '::' port:`))
        .withWaitStrategy('flyway_c', Wait.forLogMessage(`Successfully applied`))
        .withStartupTimeout(120000)
        .up();

This is my docker-compose file:

version: '3'
services:
  db:
    image: mysql:8.0.26
    environment:
      - MYSQL_DATABASE=test_db
      - MYSQL_ROOT_PASSWORD=pass
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --default-authentication-plugin=mysql_native_password
    ports:
      - '3306:3306'
      - '33060:33060'
    expose:
      - '3306'
    container_name: test_mysql
  flyway:
    image: flyway/flyway
    command: -url=jdbc:mysql://db -schemas=test_db -user=root -password=pass -connectRetries=100 migrate
    volumes:
      - .:/flyway/sql
    depends_on:
      - db
    container_name: flyway_c

Any help would be appreciated. Thanks!

EDIT:

This problem is not caused by the docker-compose. In other words, the service flyway does wait for db if they are run as docker-compose up but they fail when running inside the testcontainers npm library. So, Docker Compose wait for container X before starting Y doesn't really resolve this.

I have added the answer which I used to resolve this for me. Thanks!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

After a long session of logging and debugging, the issue seems to be the timeout. The 120000ms I specified turned out to be insufficient for the MySQL container to fire up. Increasing the timeout to say 150000ms does the trick.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!