-1
我的Docker容器从Git中提取我的Node应用程序并安装所需的依赖关系。但是,在初始运行后,随后调用Docker Start时会重新运行此逻辑。有没有一种方法可以将我的入口脚本设置为仅在调用Docker运行时从Git中提取应用程序?我假设在初始设置完成之后,我总是可以将文件写入容器,并在从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 "[email protected]"
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容器中是通常推荐的方法,并且了解node:onbuild如何工作。我正在尝试这种方法,因为我不想将源代码嵌入保存在Docker集线器上的容器中。另外,我有很多节点微服务,并且不想处理很多不同的容器。我宁愿只有一个我重用。缺点是,启动需要更长的时间(以拉取依赖和应用文件),但基于我目前的实验,它非常快。 – AnDev123 2014-12-04 17:52:22