在Dockerfile中为OpenShift初始化MySQL数据库

时间:2018-03-01 21:07:49

标签: mysql docker openshift openshift-origin openshift-3

我正在从Dockerfile在OpenShift上部署MySQL。一切顺利,我可以使用oc rsh初始化和填充数据库。但现在,我想自动化Dockerfile中的所有手动步骤。

这是我从oc rsh手动运行的命令:

mysql -u root

CREATE USER 'loyal'@'172.%' IDENTIFIED BY 'Test123';
GRANT ALL PRIVILEGES ON *.* TO 'loyal'@'172.%';

CREATE USER 'loy'@'localhost' IDENTIFIED BY 'Test123';
GRANT ALL PRIVILEGES ON *.* TO 'loyal'@'localhost';

flush privileges;

exit;exit;

mysql -u loyal -p loyal < main.sql

mysql -u loyal -p loyal

select * from BARCODE;

## I get a dump of data

这是我的Dockerfile:

FROM registry.access.redhat.com/rhscl/mysql-57-rhel7

ENV MYSQL_USER=loyal
ENV MYSQL_PASSWORD=loyal
ENV MYSQL_DATABASE=loyal
ENV MYSQL_ROOT_PASSWORD=loyal

COPY ./APP.sql /opt/app-root/src
COPY ./BARCODE.sql /opt/app-root/src
COPY ./CARD.sql /opt/app-root/src
COPY ./main.sql /opt/app-root/src

ADD users.sql /docker-entrypoint-initdb.d

我正在上面最后一行中的users.sql进行测试,因为我在Google上搜索了一个文件夹,其中配置在容器中被拾取但是我没有这样做。任何帮助将不胜感激!

以下是users.sql的外观:

mysql -u root

CREATE USER 'loyal'@'172.%' IDENTIFIED BY 'Test123';
GRANT ALL PRIVILEGES ON *.* TO 'loyal'@'172.%';

CREATE USER 'loyal'@'localhost' IDENTIFIED BY 'Test123';
GRANT ALL PRIVILEGES ON *.* TO 'loyal'@'localhost';

flush privileges;

0 个答案:

没有答案