apache2 – Script always running on ENTRYPOINT dockerfile but i only want him to run once

I tried to set up a wordpress solution (installing by myself and not using an official image). I have one container with apache, php and mariadb-client (to interrogate mariadb-server from another container)

I have another container with mariadb on it.

I use wp-cli to configure wordpress website but when i build my docker image, I can’t execute the command (inside sh file) which is

wp core config –allow-root –dbname=$MYSQL_DATABASE –dbuser=$MYSQL_USER –dbpass=$MYSQL_PASSWORD –dbhost=172.20.0.2 –dbprefix=wp –path=/var/www/html/wordpress
because my mariadb container isn’t up.

So I tried to run this script with entrypoint parameters and when I do my docker-compose up, my script is played and I have the message:

apache-php_SDV | Success: Generated ‘wp-config.php’ file.

apache-php_SDV | Error: The ‘wp-config.php’ file already exists.
My script is played every second, I tried to use CMD before and it doesn’t work, it’s like CMD wasn’t run

I have the same result if I want to put CMD after ENTRYPOINT, I can run my script only when both containers are up.

I also tried to use command on my docker-compose.yml but not helpful. Does anyone have a solution?