私の Docker コンテナーは、Git から Node App をプルし、必要な依存関係をインストールします。ただし、このロジックは、最初の実行後に Docker Start への後続の呼び出しで再実行されます。Docker run が呼び出されたときにのみ Git からアプリをプルするように Entrypoint スクリプトをセットアップする方法はありますか? 初期セットアップが完了した後、常にファイルをコンテナーに書き込み、Git からプルする前にそのファイルを確認できると思いますか? この動作を実現するためのより良い、よりクリーンな方法はありますか?
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 .