Merge pull request #437 from philtrep/fix-mysql-change-env

Added proper creation of mysql user, removal of default homestead user
This commit is contained in:
Philippe Trépanier 2016-11-18 10:12:37 -05:00 committed by GitHub
commit e5a8fb9c95
3 changed files with 29 additions and 7 deletions

View File

@ -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 #######################################

View File

@ -2,8 +2,26 @@ FROM mysql:5.6
MAINTAINER Mahmoud Zalt <mahmoud@zalt.me>
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

3
mysql/startup Normal file
View File

@ -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';