Dockerfile在入口点执行其他脚本 [英] Dockerfile execute additional scripts in entrypoint
问题描述
我正在从 init.sh
脚本,将其作为Dockerfile的入口点运行,如下所示:
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"]
在我的 init中.sh
我正在执行父容器的入口点脚本,但是由于此脚本不会退出并且不会在后台运行,因此我的添加操作永远不会执行。我尝试了几种不同的调用父脚本的方法,包括 source entry.sh
, / bin / sh /entry.sh
和(/ entry.sh)
。我也尝试使用 /entry.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?
编辑:我的初始化脚本
#!/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"
推荐答案
我认为基于这样的事实,即在mysql运行之后,还有其他方法可以运行初始查询,您应该尝试从另一个角度解决这个问题。
例如,您可以使用卷来设置 ./ conf / docker-entrypoint-initdb.d
之类的内容,例如这显示
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
编辑:
您还可以将.sh文件放在目录中,不仅是.sql文件。
它们按字母顺序执行。
此处和此处
这篇关于Dockerfile在入口点执行其他脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!