Initialise database using sql script with environment variables

I want to use a script "setup.sql" placed in /etc/mysql/mariadb.conf.d to initialise a database. The script contains an insert statement INSERT INTO virtual_domains (name) VALUES ('mydomain.tld');

I want to replace mudomain.tld with $MYDOMAIN, defined in compose.yaml. Is this possible?

Answer Answered by Daniel Black in this comment.

Thanks, this was the answer. Apologies for my incorrect path, I didn't understand the difference between .sql and .sh files.

I think you mean /docker-entrypoint-initdb.d.

On https://hub.docker.com/_/mariadb under 'Initializing the database contents' you can have a script.

Have a create_virt_domain.sh file without any execute permissions with the contents:

docker_process_sql <<<'INSERT INTO virtual_domains (name) VALUES ('$MYDOMAIN');'
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.