Reputation: 443
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.
Upvotes: 1
Views: 556
Reputation: 15080
You can create a healthcheck, for example:
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 40s
Upvotes: 1