TL; DR
entrypoint.sh
#!/bin/bash
#Preprocessing
echo "Do something before execution docker-entrypoint.sh"
#Add this line
source /usr/local/bin/docker-entrypoint.sh "$@"
#Post-processing
echo "Do something after execution docker-entrypoint.sh"
$ chmod +x entrypoint.sh
COPY entrypoint.sh /usr/local/bin
# ENTRYPOINT ["docker-entrypoint.sh"]
ENTRYPOINT ["entrypoint.sh"]
CMD ["apache2-foreground"]
There were a lot of things I wanted to do with the official WordPress Docker Image. However, before launching WordPress, I did not know what to do when I wanted to execute ShellScript, such as inserting data into the DB, so I will leave it.
docker-entrypoint.sh
In the official Docker Image, by default, the startup script is saved as "docker-entrypoint.sh", and by executing the script at startup, the application you want to execute in that Container is started. It is often taken.
In many cases, it is a method that is often used for images such as applications that only need to be started after setting environment variables, but it is a little inconvenient if you want to perform other processing before and after starting.
However, if you use your own startup script, you will not be able to benefit from the latest version of docker-entrypoint.sh due to the image upgrade.
In such a case, consider having the execution of docker-entrypoint.sh in your own startup script.
The solution is to use source to expand docker-entrypoint.sh and use " $ @ "
to pass all the arguments.
Write a script like the following. It is important that the source line inherits all the arguments it receives.
entrypoint.sh
#!/bin/bash
#Preprocessing
echo "Do something before execution docker-entrypoint.sh"
#Add this line
source /usr/local/bin/docker-entrypoint.sh "$@"
#Post-processing
echo "Do something after execution docker-entrypoint.sh"
The script you create gives you executable privileges.
$ chmod +x entrypoint.sh
COPY entrypoint.sh /usr/local/bin
# ENTRYPOINT ["docker-entrypoint.sh"]
ENTRYPOINT ["entrypoint.sh"]
CMD ["docker-entrypoint.Arguments to sh"]
I was impressed because I thought only about the source command and the command used to update zshrc. It's convenient when dealing with WordPress Images, so come on!
Recommended Posts