I’m working on Debian-based Virtual Box
I have docker-compose yaml file:
version: '3'
services:
mydb:
build: ./db/
networks:
- dockercompose-frontend
volumes:
- server_db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=debian
healthcheck:
test: ["CMD", "mariadb-admin", "ping", "-h", "localhost"]
interval: 10s
timeout: 15s
retries: 5
frontend:
build: .
ports:
- "8080:80"
networks:
- dockercompose-frontend
environment:
PMA_HOST=mydb
PMA_PORT=3306
volumes:
server_db:
driver: local
networks:
dockercompose-frontend:
And two Dockerfiles for each of the services, where I just install necessary images.
FROM mariabd:latest
RUN apt-get update && apt-get install -y iputils-ping
and
FROM phpmyadmin:5.2.0-apache
RUN apt-get update && apt-get install -y iputils-ping
When I’m using docker compose up
(without -d mode):
frontend-1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain nam e, using 172.25.0.2. Set the ServerName directive globally to suppress this message
When I’m using docker compose up -d
and checks Health State for mydb it throws:
{
"Status":"starting",
"FailingStreak": 2,
"Log": [{"Start": "2024-02-19T10:05:48.178379963-05:00",
"End": 2024-02-19T10:05:48.240662846-05:00",
"ExitCode": 1,
"Output":"u0007mariadb-admin: connect to server a t 'localhost failednerror: 'Can't connect to local server through socket '/run/mysqld/mysqld.sock (2)
'Check that mariadbd is running and that the socket: '/run/mysqld/mysqld.sock' exists!"
}
Also,
docker exec dockercompose-mydb-1 service mariadb status
throws "Mariadb service is stopped"
After
docker exec dockercompose-mydb-1 service mariadb start
it throws exit code 1 (failure).
2
Answers
first, update the syntax in health check part as there’s error with quotes to
second specify the port in mariadb service
also make sure that the network driver is not equal to none, it’s type is equal to bridge for example.
you can add "depends_on" in frontend service so the container is not created unless mariaDB is up successfully.
There’s a healthcheck.sh script for the very purpose.
So there’s no need to additional grants, users to make this happen.
The other problem with
mariadb-admin ping
is without--protocol tcp
it can return healthly during the initialization phases of the startup.