简体   繁体   English

启动 docker 服务时运行多个命令

[英]Run multiple commands while starting docker services

I am trying to run two different commands when doing docker-compose up.在执行 docker-compose up 时,我试图运行两个不同的命令。

My command: parameter looks like:我的command:参数看起来像:

gunicorn --reload analytics_api:api --workers=3 --timeout 10000 -b :8083 && exec python /analytics/model_download.py

But when I run this the container fails with the error:但是当我运行它时,容器失败并出现错误:

gunicorn: error: unrecognized arguments: && exec python /analytics/model_download.py gunicorn:错误:无法识别的参数:&& exec python /analytics/model_download.py

The second part of the command python /analytics/model_download.py , is used to download some dependencies from a sharedpath to a directory inside the container.命令python /analytics/model_download.py的第二部分用于将一些依赖项从共享路径下载到容器内的目录。

I want to run it while the service is up, not during the build.我想在服务启动时运行它,而不是在构建期间。

What is going wrong here?这里出了什么问题?

One way can be to have a startup shell script as the command which has both these entries一种方法是将启动 shell 脚本作为具有这两个条目的command

startup.sh启动文件

#start this in background if the other process need not wait for completion
exec python /analytics/model_download.py &
gunicorn --reload analytics_api:api --workers=3 --timeout 10000 -b :8083

while true 
 do
   sleep 5
done

Adding bash -c before the command solved the problem.在命令解决问题之前添加bash -c

The command value will look like:命令值将如下所示:

bash -c "python model_download.py && gunicorn --reload analytics_api:api -- workers=3 --timeout 10000 -b :8083"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM