docker-compose mysql health check inline complex command:
serivces:
mysql:
image: mysql:latest
volumes:
- ./init-data:/docker-entrypoint-initdb.d
healthcheck:
test:
- CMD-SHELL
- if [[ -z "$(ls -A /docker-entrypoint-initdb.d)" ]]; then
mysql -u root -p123456 -e 'select 0'
else
mysql -u root -p123456 --database my_db -e 'show tables' | [ $(wc -l) -gt 100 ]
fi
interval: 10s
timeout: 10s
retries: 50
Mysql not healthy.
It works without if/else in both cases.