I
I
Igor2019-10-01 01:35:36
MySQL
Igor, 2019-10-01 01:35:36

Docker, MySql is running?

Colleagues, hello!
How to determine if mysql is running in a container?
After all the containers are running, the database is not yet available, (it starts, creates tables, databases if there are none)
The first run is quite long.
I need to somehow determine that the database is ready.
The code below is not suitable, as it determines the fact that the container is running, but I do not need it.
I need something similar to this.

echo "Waiting for DB to start up..."
while(docker inspect rosinter.db --format '{{.State.Running}}' -eq 'false'){
    Start-sleep 5
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Vasilyev, 2019-10-01
@IgorPI

while ! mysqladmin ping -h"$DB_HOST" --silent; do
    sleep 1
done

Well, or compose ala:
version: "2.1"
services:
    api:
        build: .
        container_name: api
        ports:
            - "8080:8080"
        depends_on:
            db:
                condition: service_healthy
    db:
        container_name: db
        image: mysql
        ports:
            - "3306"
        environment:
            MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
            MYSQL_USER: "user"
            MYSQL_PASSWORD: "password"
            MYSQL_DATABASE: "database"
        healthcheck:
            test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
            timeout: 20s
            retries: 10

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question