I am currently blocked, I want to build a data base when I build a Dockerfile. But I got an error and i don't understand why. Thanks for your help.
Here my Dockerfile
FROM mariadb:latest
WORKDIR /sql-files
ADD sql/ /sql-files/
ENV MYSQL_ROOT_PASSWORD test123
ENV MYSQL_DATABASE testDB
ENV MYSQL_USER toto
ENV MYSQL_PASSWORD test123
RUN apt-get update && apt-get -y install vim && chmod +x insertDB.sh && sh insertDB.sh
EXPOSE 3306
Here my insertDB.sh
#!/bin/sh
/usr/bin/mysqld_safe --skip-grant-tables &
sleep 5
mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD $MYSQL_DATABASE < test.sql
and finaly my test.sql script
CREATE TABLE IF NOT EXISTS test (
id int NOT NULL AUTO_INCREMENT,
name varchar(32) NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO test (name) VALUES
('Toto'),
('Jack'),
('Titi');
So when i execute my docker file with the command docker build -t maria . I get this error:
Processing triggers for libc-bin (2.19-18+deb8u10) ...
171112 18:12:53 mysqld_safe Logging to syslog.
171112 18:12:54 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
ERROR 1049 (42000): Unknown database 'testDB'
The command '/bin/sh -c apt-get update && apt-get -y install vim && chmod +x insertDB.sh && sh insertDB.sh' returned a non-zero code: 1
What am i missed ?