I’m building an image from this Dockerfile:
COPY init_db.sh /tmp/init_db.sh
COPY latest.sql /tmp/latest.sql
RUN chmod +x /tmp/init_db.sh
RUN /bin/bash -c /tmp/init_db.sh
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/init_db.sh
CMD /bin/bash -c /tmp/init_db.sh
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