Initializing MySQL DB Fails

I’m building an image from this Dockerfile:

FROM mysql:5.6
COPY /tmp/
COPY latest.sql /tmp/latest.sql
RUN chmod +x /tmp/
RUN /bin/bash -c /tmp/

With this init script:

service mysql start
mysql -uroot -proot1234 -e "CREATE DATABASE my_db;"
mysql my_db < /tmp/latest.sql
service mysql stop

The build seems to go OK, but when I start up a container, the DB changes the script makes aren’t available.

It’s probably something simple. Any ideas? Thanks.

don’t u need to login again to execute the script? (when the 1st mysql command ended u were logged out)

mysql -uroot -proot1234 my_db < /tmp/latest.sql

Right you are. That’s actually in the script I’m using. The script runs without error. But when I start a container using the resulting image, the database in the container hasn’t been initialized. ???

run happens at build time, I suspect u want to change those to CMD to execute at run time.

CMD chmod +x /tmp/
CMD /bin/bash -c /tmp/

note that cmd will happen on EVERY Docker run, so hopefully its not a shared database

I just had to fix one of my images the same way