我是个新的码头工人,容器泊坞窗,我想创建一个容器中运行多个服务, 使用该文档: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