Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

262
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda