I am trying to create multiple databases when a MySQL container starts up.
According to https://github.com/docker-library/mysql/pull/18, I can mount or copy my scripts in the /docker-entrypoint-initdb.d
of the image and they will be executed automatically on start up.
However my scripts are not at all executed. Seems like the docker-entrypoint.sh
doesn't see files in the /docker-entrypoint-initdb.d
directory.
This is my Dockerfile:
FROM mysql
ADD script.sql /docker-entrypoint-initdb.d/script.sql
RUN chmod -R 775 /docker-entrypoint-initdb.d
ENV MYSQL_ROOT_PASSWORD mypass
This is my script.sql
:
CREATE DATABASE mydb;
CREATE DATABASE mydb2;
I build and run the container:
$ docker build -t mysql .
$ docker run -v data_volume:/var/lib/mysql --name somedb -d mysql
When I access the container in tty I can see that the script.sql
is in the /docker-entrypoint-initdb.d
but is not executed.
I have seen the docker logs -f somedb
output but there is no error.
I have tried with .sh
file, I also have tried with Maria-db, the result is the same.
What could be the problem?