我正在从 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;