1

I have the following configuration:

services:
  db:
    image: mysql:5.6
    command: --default-authentication-plugin=mysql_native_password --sql-mode=""
    volumes:
      - ./schema:/docker-entrypoint-initdb.d
    ports:
      - 3309:3306
    environment:
      MYSQL_ROOT_PASSWORD: test
      MYSQL_DATABASE: test    

  migration-tool:
        depends_on:
          - db
        build:
            context: ../MigrationTool.MigrationTool/
            dockerfile: Dockerfile.migrate

The db service executes some long running inserts into the database but migration-tool service will also want to create a database(with inserts) on the db service image, this will cause some exceptions into the migration-tool service, precisely, the mysql db image refuses the connection from the migraton-tool image. Everything works fine, only after the db service inserts are done, but this operation usually takes a few minutes.

I need a way to control the start of the 2nd image(migration-tool) only after all the inserts are done in the 1st image. Or maybe there's a better solution to the described scenario. Thanks.

Radu Olteanu
  • 393
  • 4
  • 17
  • Compose isn't great for this: it doesn't have built-in support for waiting for other containers to be ready, or for long-running containers to advance past some point, and it generally expects all containers to be long-running and not task-oriented. [Docker Compose wait for container X before starting Y](https://stackoverflow.com/questions/31746182/docker-compose-wait-for-container-x-before-starting-y) might give you some inspiration; the techniques there can often be reused outside of a Compose context. – David Maze Oct 16 '20 at 11:46
  • may this be useful https://docs.docker.com/compose/startup-order/ – badger Oct 16 '20 at 12:32

1 Answers1

1

You can create a healthcheck, for example:

healthcheck:
  test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
  interval: 1m30s
  timeout: 10s
  retries: 3
  start_period: 40s
Ron van der Heijden
  • 14,803
  • 7
  • 58
  • 82