I've read recent post Setting up MySQL and importing dump within Dockerfile but couldn't find an answer.
What I want is to build custom mysql image with created database, users and some other data. Here is my Dockerfile(simplified):
FROM mysql:5.7
ENV MYSQL_ROOT_PASSWORD=root
RUN service mysql start && \
mysql -uroot -p$MYSQL_ROOT_PASSWORD -e "CREATE DATABASE mydb;" && \
mysql -uroot -p$MYSQL_ROOT_PASSWORD -e "SHOW databases;" && \
service mysql stop
ENTRYPOINT service mysql start && /bin/sh
Image is built successfully and mydb database is listed as output of "SHOW DATABASES". But when I run container based on this image I see that root password is empty and mydb database is missing.
How can I fix that? Thanks?