How to use volumes and init script in docker compose?

Hello,
I’m writing a docker-compose file for our application as follows:

version: '3.6'

services:
 db:
  container_name: db
  image:  mariadb:10.3
  restart: always
  command: --default-authentication-plugin=mysql_native_password
  env_file:
   - .env
  ports:
   - "3306:3306"
  volumes:
   - ./db_init:/docker-entrypoint-initdb.d
   - ./db_data:/var/lib/mysql

 adminer:
  image: adminer
  restart: always
  ports:
   - 8080:8080

But wonder if this correct or not?
I mean, in the db service, i have a volume that contains init script for database, and have another volume for persistent storage. But would like to know, what would happen if the docker-compose file is killed then restarted? should it rerun again and recreate database? if so, how i can tell it, not to do so?
By the way, i tested this but got frustrating messages saying:
" Recreating database "
Thank you in advance,

The sql script available in the container path /docker-entrypoint-initdb.d will only be executed when /var/lib/mysql does not contain database data. Meaning: it is only intended for the initial setup.

Since you use a bind-mount for /var/lib/mysql, the data created in the container should be persisted in a folder on the host - it should remain there regardless whether the container is running, restarted or deleted.

Can you extend what you mean by “if the docker-compose file is killed and restarted”?

A compose file is “just” a configured that is read by docker-compose, converted into api calls and send to the docker engine, which applies whatever was send to it. The job of docker-compose ends there.

N.B.: your compose file uses volume-binds (sometimes refered to as bind-mounts), those are not volumes in the sense of volumes. Your binds won’t be listed in docker volume ls, like “real” volumes would be.