Node Docker容器 – 运行时从Git Repo拉取节点应用程序源

我正在尝试创build一个通用的Docker镜像,并且可以与我的所有Node应用程序一起使用。 我当前的docker映像和逻辑从运行docker镜像时作为命令行arg接收到的指定Git仓库中抽取应用程序的源代码。 这里是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 . 

我知道Dockerbuild议使用exec命令不要让你的进程通过SIGKILL杀死,当容器停止和超时? 有没有关于git clone命令和npm install命令在容器停止时运行,因为我不使用exec? 有没有办法解决这个在我的入口脚本?