节点Docker容器 - 在运行时从Git Repo中拉出节点应用程序源

时间:2014-12-01 18:39:46

标签: node.js bash docker dockerhub dockerfile

我正在尝试创建一个通用的docker镜像,可以与我的所有Node应用程序一起使用。我当前的docker镜像和逻辑从运行docker镜像时作为命令行arg接收的指定Git repo中提取应用程序的源。以下是docker文件和入口点逻辑的代码:

Dockerfile:

# Generic Docker Image for Running Node app from Git Repository
FROM    node:0.10.33-slim
ENV NODE_ENV production

# Add script to pull Node app from Git and run the app
COPY docker-node-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

EXPOSE  8080
CMD ["--help"]

入口点脚本:

#!/bin/bash
set -e
# Run the command passed in if it isn't to start a node app
if [ "$1" != 'node-server' ]; then
   exec "$@"
fi
# Logic for pulling the node app and starting it
cd /usr/src
# try to remove the repo if it already exists
rm -rf node-app; true
echo "Pulling Node app's source from $2"
git clone $2 node-app
cd node-app
# Check if we should be running a specific commit from the git repo
if [ ! -z "$3" ]; then
  echo "Changing to commit $3"
  git checkout $3
fi
npm install
echo "Starting the app"
exec node .

我知道Docker建议使用exec命令,当容器停止并且超时时,不会通过SIGKILL杀死你的进程?当容器停止时,是否有关于git clone命令和npm install命令运行的问题,因为我没有使用exec?有没有办法在我的入口点脚本中解决这个问题?

0 个答案:

没有答案