0

I am deploying MySQL on OpenShift from a Dockerfile. Everything went well and I am able to initialize and populate the database by using oc rsh. But now, I want to automate all the manual steps in my Dockerfile.

Here's the commands I run manually from 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

Here's my 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

I am testing with users.sql in the last line above as I googled that is a folder where the configuration gets picked up in a container but that isnt doing it for me. Any help would be much appreciated!

Here's how users.sql looks like:

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;
redhatter
  • 63
  • 2
  • 4

0 Answers0