diff --git a/docker-compose.yml b/docker-compose.yml index 22848b1..1a35157 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -112,16 +112,17 @@ services: ### MySQL Container ######################################### mysql: - build: ./mysql + build: + context: ./mysql + args: + - MYSQL_DATABASE=homestead + - MYSQL_USER=homestead + - MYSQL_PASSWORD=secret + - MYSQL_ROOT_PASSWORD=root volumes: - mysql:/var/lib/mysql ports: - "3306:3306" - environment: - MYSQL_DATABASE: homestead - MYSQL_USER: homestead - MYSQL_PASSWORD: secret - MYSQL_ROOT_PASSWORD: root ### MariaDB Container ####################################### diff --git a/mysql/Dockerfile b/mysql/Dockerfile index 73bd833..372adac 100644 --- a/mysql/Dockerfile +++ b/mysql/Dockerfile @@ -2,8 +2,26 @@ FROM mysql:5.6 MAINTAINER Mahmoud Zalt +ADD startup /etc/mysql/startup + +RUN chown -R mysql:root /var/lib/mysql/ + +ARG MYSQL_DATABASE=homestead +ARG MYSQL_USER=homestead +ARG MYSQL_PASSWORD=secret +ARG MYSQL_ROOT_PASSWORD=root + +ENV MYSQL_DATABASE=$MYSQL_DATABASE +ENV MYSQL_USER=$MYSQL_USER +ENV MYSQL_PASSWORD=$MYSQL_PASSWORD +ENV MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD + +RUN sed -i 's/MYSQL_DATABASE/'$MYSQL_DATABASE'/g' /etc/mysql/startup && \ + sed -i 's/MYSQL_USER/'$MYSQL_USER'/g' /etc/mysql/startup && \ + sed -i 's/MYSQL_PASSWORD/'$MYSQL_PASSWORD'/g' /etc/mysql/startup + ADD my.cnf /etc/mysql/conf.d/my.cnf -CMD ["mysqld"] +CMD ["mysqld", "--init-file=/etc/mysql/startup"] EXPOSE 3306 diff --git a/mysql/startup b/mysql/startup new file mode 100644 index 0000000..88ecce2 --- /dev/null +++ b/mysql/startup @@ -0,0 +1,3 @@ +DROP USER 'homestead'; +CREATE DATABASE IF NOT EXISTS MYSQL_DATABASE; +GRANT ALL ON `MYSQL_DATABASE`.* TO 'MYSQL_USER'@'%' IDENTIFIED BY 'MYSQL_PASSWORD'; \ No newline at end of file