Docker mark unhealthy service so fast

I have a service configuration like this in the docker-compose file:

callflow_database:
container_name: callflow_database
ports:
- 3307:3306
restart: unless-stopped
environment:
- MYSQL_ROOT_PASSWORD=root_password
healthcheck:
test: [“CMD”, “mysqladmin” ,“ping”, “-h”, “localhost”, “-u”, “root”, “–password”, “primasvn”]
timeout: 20s
retries: 10
volumes:
- callflow_database_volume:/var/lib/mysql
build: ./callflow_database

I also followed the correct way of initial database with data. And this is my Dockerfile for building callfow_datbase:

FROM mysql:8.2.0

WORKDIR /db

COPY init.sql /docker-entrypoint-initdb.d/

RUN sed -i ‘s/bind-address\s*=\s127.0.0.1/bind-address = 0.0.0.0/’ /etc/my.cnf &&
sed -i '/^#\s
log_error/s/^# //’ /etc/my.cnf ||
echo “log_error = /var/log/mysql/error.log” >> /etc/my.cnf

I built the serivce with docker build and i tested it ran normally after a few minutes to run init.sql ofcouse.

But when i run docker compose up. Instead of retry 20 times and each time 20s max. Docker immediately marked my database service as Unhealthy. Here is the log:

callflow_database | 2024-01-12 04:08:01+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.2.0-1.el8 started.
callflow_database | 2024-01-12 04:08:01+00:00 [Note] [Entrypoint]: Switching to dedicated user ‘mysql’
callflow_database | 2024-01-12 04:08:01+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.2.0-1.el8 started.
callflow_database | 2024-01-12 04:08:02+00:00 [Note] [Entrypoint]: Initializing database files
callflow_database | 2024-01-12T04:08:02.527250Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
callflow_database | 2024-01-12T04:08:02.531890Z 0 [Warning] [MY-011068] [Server] The syntax ‘–skip-host-cache’ is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
callflow_database | 2024-01-12T04:08:02.532066Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.2.0) initializing of server in progress as process 80
callflow_database | 2024-01-12T04:08:02.535916Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
callflow_database | 2024-01-12T04:08:02.535929Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
callflow_database | 2024-01-12T04:08:02.536465Z 0 [ERROR] [MY-010119] [Server] Aborting
callflow_database | 2024-01-12T04:08:02.536778Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.2.0) MySQL Community Server - GPL.
callflow_database | 2024-01-12T04:08:02.537363Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
callflow_database | 2024-01-12 04:08:06+00:00 [Note] [Entrypoint]: Switching to dedicated user ‘mysql’
callflow_database | 2024-01-12 04:08:06+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.2.0-1.el8 started.
callflow_database | 2024-01-12 04:08:08+00:00 [Note] [Entrypoint]: Initializing database files
callflow_database | 2024-01-12T04:08:08.089266Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
callflow_database | 2024-01-12T04:08:08.092120Z 0 [Warning] [MY-011068] [Server] The syntax ‘–skip-host-cache’ is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
callflow_database | 2024-01-12T04:08:08.092266Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.2.0) initializing of server in progress as process 79
callflow_database | 2024-01-12T04:08:08.095048Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
callflow_database | 2024-01-12T04:08:08.095059Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
callflow_database | 2024-01-12T04:08:08.108271Z 0 [ERROR] [MY-010119] [Server] Aborting
callflow_database | 2024-01-12T04:08:08.108497Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.2.0) MySQL Community Server - GPL.
callflow_database | 2024-01-12T04:08:08.108946Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
callflow_database | 2024-01-12T04:14:07.736470Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
callflow_database | 2024-01-12T04:14:07.739611Z 0 [Warning] [MY-011068] [Server] The syntax ‘–skip-host-cache’ is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
callflow_database | 2024-01-12T04:14:07.739866Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.2.0) initializing of server in progress as process 80
callflow_database | 2024-01-12T04:14:07.748386Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
callflow_database | 2024-01-12T04:14:07.748396Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
callflow_database | 2024-01-12T04:14:07.751222Z 0 [ERROR] [MY-010119] [Server] Aborting
callflow_database | 2024-01-12T04:14:07.751465Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.2.0) MySQL Community Server - GPL.
callflow_database | 2024-01-12T04:14:07.751908Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
dependency failed to start: container callflow_database is unhealthy

Docker verison: Docker version 24.0.7, build afdd53b
OS: Debian 11

It seems the database is restarting all the time, your log is probably from the service, not from a single container.

Try docker ps -a to see individual containers.