容器的postStart挂钩中的多个命令 [英] multiple command in postStart hook of a container
本文介绍了容器的postStart挂钩中的多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在kubernetes部署yaml文件中,是否有一种简单的方法可以在容器的postStart挂钩中运行多个命令?
in a kubernetes Deployment yaml file is there a simple way to run multiple commands in the postStart hook of a container?
我正在尝试做这样的事情:
I'm trying to do something like this:
lifecycle:
postStart:
exec:
command: ["/bin/cp", "/webapps/myapp.war", "/apps/"]
command: ["/bin/mkdir", "-p", "/conf/myapp"]
command: ["touch", "/conf/myapp/ready.txt"]
但是它不起作用. (看起来只执行了最后一条命令)
But it doesn't work. (looks like only the last command is executed)
我知道我可以在容器映像中嵌入脚本并在其中调用它...但是我希望能够在yaml文件中自定义这些命令,而无需触及容器映像.
I know I could embed a script in the container image and simply call it there... But I would like to be able to customize those commands in the yaml file without touching the container image.
谢谢
推荐答案
只允许一个command
,但是您可以像这样使用sh -c
Only one command
allowed, but you can use sh -c
like this
lifecycle:
postStart:
exec:
command:
- "sh"
- "-c"
- >
if [ -s /var/www/mybb/inc/config.php ]; then
rm -rf /var/www/mybb/install;
fi;
if [ ! -f /var/www/mybb/index.php ]; then
cp -rp /originroot/var/www/mybb/. /var/www/mybb/;
fi
这篇关于容器的postStart挂钩中的多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文