I have a project (written in ruby) which I want to run in a docker image. The project source code is stored in a private git repo, the image is created as usual by Dockerfile. The project is huge and so git clone takes relatively long.
The problem is that, I'm not sure how (when/where) to clone the git repo to the docker image properly. I can clone the git repository to the temp directory and copy the source code by COPY command in Dockerfile. I don't like to do that since I would have to maintain the second clone in the temp dir.
Or, I can clone the repo within the docker image. The problem is my ssh-key which I can't reasonably keep in the image. I can add only "my own" keys to the git server which allow to access everything.
So, I created a script like this:
UUID=`uuid`
docker run \
-v $HOME/.ssh:/home/user/.ssh:ro\
--name=$UUID \
-it $1 /scripts/git-clone-update.sh
docker commit $UUID $1
docker rm $UUI
git-clone-update.sh clones the project if it doesn't exist or just updates if it does. The keys are mounted to the .ssh for that. It works great. I can update the code in the image easily by just calling the script passing the image name as an argument. The only problem is Config.Cmd which always changes to /scripts/git-clone-update.sh.
Any idea how to keep the original Config.Cmd? What is the best practice cloning the private ropo in/to the docker image?
Thx