[英]How to run two processes with dockerfile?
我需要運行 uvicorn 服務器進程和我的 python 腳本(這是另一個進程)。 由於 uvicorn 啟動了一個不會結束的進程,因此第二個命令將不會啟動。 所以我問你是否知道一些解決方法來解決這個問題。
我試圖執行此命令:
CMD cd Manager ; uvicorn ManagerBot:app --host 0.0.0.0 --port 8000 && python ManagerBot.py
還有這個:
CMD cd Manager ; uvicorn ManagerBot:app --host 0.0.0.0 --port 8000 ; python ManagerBot.py
但是腳本沒有啟動(只有 uvicorn 服務器啟動)我提醒你,腳本是另一個不會結束的進程,所以“viceversa”將不起作用。
創建一個包裝器腳本,例如run.sh
:
#!/bin/bash
# Start the first process
cd Manager
uvicorn ManagerBot:app --host 0.0.0.0 --port 8000 &
# Start the second process
python ManagerBot.py &
# Wait for any process to exit
wait -n
# Exit with status of process that exited first
exit $?
然后,在 Dockerfile 中:
...
COPY run.sh /run.sh
RUN chmod +x /run.sh
ENTRYPOINT ["/run.sh"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.