FROM debian:buster

ARG DB_NAME
ARG DB_USER
ARG DB_PSWD

RUN	apt update && apt install -y \
	mariadb-client \
	mariadb-server
RUN rm -rf /var/lib/apt/lists/*

# configure wp database
RUN	service mysql start && \
	mariadb --execute="CREATE DATABASE ${DB_NAME};" && \
	mariadb --execute="CREATE USER '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PSWD}';" && \
	mariadb --execute="GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'localhost' with grant option;"

# # config file 50-server.cnf :
# # uncomment port = 3306
# RUN sed -i "s/^#port/port /g" /etc/mysql/mariadb.conf.d/50-server.cnf
# # comment bind-address = 127.0.0.1
# RUN sed -i "s/^bind-address /#bind-address/g" /etc/mysql/mariadb.conf.d/50-server.cnf
COPY ./conf/50-server.cnf ./

ENTRYPOINT [ "mysqld" ]

