我是個新的碼頭工人,容器泊塢窗,我想創建一個容器中運行多個服務, 使用該文檔:Run multiple services in a container與運行Java應用程序和Web服務器不工作
我已經成功地得到Java和安裝在containe的NodeJS,最終導致在Dockerfile結束作爲入口點運行此腳本:
#!/bin/bash
# Start the first process
/tmp/cliffer/bin/startup.sh &
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start my_first_process: $status"
exit $status
fi
# Start the second process
npm start &
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start my_second_process: $status"
exit $status
fi
# Naive check runs checks once a minute to see if either of the processes exited.
# This illustrates part of the heavy lifting you need to do if you want to run
# more than one service in a container. The container will exit with an error
# if it detects that either of the processes has exited.
# Otherwise it will loop forever, waking up every 60 seconds
while /bin/true; do
PROCESS_1_STATUS=$(ps aux |grep -q my_first_process |grep -v grep)
PROCESS_2_STATUS=$(ps aux |grep -q my_second_process | grep -v grep)
# If the greps above find anything, they will exit with 0 status
# If they are not both 0, then something is wrong
if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 ]; then
echo "One of the processes has already exited."
exit -1
fi
sleep 60
done
這兩個服務都在後臺運行,結果是npm start,啓動一個web服務器,但立即關閉。 這是輸出IM從npm start &
[--:--:--][CONSOLE] [09:19:11] [Start] Listening at port 3000
[09:19:11] [Stop] Shutting down
讓我單獨在自己的容器它的作品完美運行與每個服務的容器。
有什麼想法爲什麼?
不回答你的問題,但值得一提的是,一般建議每個容器運行1個服務,如果你想要幾個服務,你可以使用docker-compose。話雖如此,當你說他們單獨工作時,它是否與ENTRYPOINT指向一個bash腳本?或者直接指向「npm start」? – Joel