I'm building a lamp
container for development work from glats/alpine-lamp. I want to run some additional sql commands (create a DB and some test users) after the container loads. I've created a new init.sh
script that I'm running as my Dockerfile's entrypoint, like this:
FROM glats/alpine-lamp
ENV MYSQL_ROOT_PASSWORD=password
COPY init.sh /init.sh
RUN chmod u+x /init.sh
ENTRYPOINT ["/init.sh"]
In my init.sh
I'm executing the parent container's entrypoint script, but since this script doesn't exit and doesn't run in the background, my additions never get executed. I've tried a few different ways of calling the parent script, including source entry.sh
, /bin/sh /entry.sh
, and (/entry.sh)
. I also tried sending it to the background using /entry.sh &
, though this didn't work either.
What's the right way to add additional entrypoint scripts to a container when the parent script doesn't exit?
EDIT: my init script
#!/bin/sh
#run the parent container's entry script
/entry.sh &
# now run the rest of the stuff that needs to happen
mysql -u root -ppassword -e "CREATE DATABASE IF NOT EXISTS mydatabase"
I think based on the fact that there are other ways to run initial queries after the mysql is running, you should try to approach this from another angle.
For example you can use volumes to set the ./conf/docker-entrypoint-initdb.d
something like what this is showing
EDIT: you can also put .sh files in the directory, it's not only .sql files. They are executed in alphabetical order. There is a better explanation here and here