The Docker Compose healthcheck fails, but I can login to database just fine. What have I missed?
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bc192ff6496f mariadb:10.11.10-ubi9 "docker-entrypoint.s…" 4 minutes ago Up 4 minutes (unhealthy) 0.0.0.0:4306->3306/tcp, [::]:4306->3306/tcp spring-boot-db-1
The healthcheck command is:
$ mysql -u spring -P 4306 -pspring spring -Bse 'SELECT 1'
1
Logging in from command line:
$ mysql -u spring -P 4306 -pspring spring
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.11.10-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [spring]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| spring |
+--------------------+
2 rows in set (0.001 sec)
And compose.yml
services:
db:
image: mariadb:10.11.10-ubi9
volumes:
- mysqldata:/var/lib/mysql
ports:
- 4306:3306
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: spring
MYSQL_PASSWORD: spring
MYSQL_DATABASE: spring
healthcheck:
test: "mysql -u spring -P 4306 -pspring spring -Bse 'SELECT 1'"
start_interval: 3s
start_period: 15s
interval: 2m
retries: 3
timeout: 5s
volumes:
mysqldata:
Turns out the health check is done from inside the container, so I need to be using the internal port, not the mapped port, ie, 3306
, nor 4306
.
So the health check command should be
"mysql -u spring -P 3306 -pspring spring -Bse 'SELECT 1'"