Dockerfile 在入口点执行额外的脚本
Dockerfile execute additional scripts in entrypoint
我正在为 glats/alpine-lamp 的开发工作构建一个 lamp
容器。我想在容器加载后 运行 一些额外的 sql 命令(创建数据库和一些测试用户)。我创建了一个新的 init.sh
脚本,我 运行 将其作为我的 Dockerfile 的入口点,如下所示:
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
中,我正在执行父容器的 entrypoint script,但是由于此脚本不会退出并且不会 运行 在后台,所以我的添加永远不会得到执行。我尝试了几种调用父脚本的不同方式,包括 source entry.sh
、/bin/sh /entry.sh
和 (/entry.sh)
。我也尝试使用 /entry.sh &
将其发送到后台,尽管这也不起作用。
当父脚本不退出时,向容器添加额外入口点脚本的正确方法是什么?
编辑:我的初始化脚本
#!/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"
我正在为 glats/alpine-lamp 的开发工作构建一个 lamp
容器。我想在容器加载后 运行 一些额外的 sql 命令(创建数据库和一些测试用户)。我创建了一个新的 init.sh
脚本,我 运行 将其作为我的 Dockerfile 的入口点,如下所示:
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
中,我正在执行父容器的 entrypoint script,但是由于此脚本不会退出并且不会 运行 在后台,所以我的添加永远不会得到执行。我尝试了几种调用父脚本的不同方式,包括 source entry.sh
、/bin/sh /entry.sh
和 (/entry.sh)
。我也尝试使用 /entry.sh &
将其发送到后台,尽管这也不起作用。
当父脚本不退出时,向容器添加额外入口点脚本的正确方法是什么?
编辑:我的初始化脚本
#!/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"