In the development debugging process, you need to constantly update the code to the Git library, and then use the latest code in the GIT library to update the running Docker container, there are now two ways, it is recommended to use the second.
1. Execute the git command directly in the container and update the directories and files in the container (not recommended)
1) First, when building the container image file, define the GIT library in the Dockfile file and set the code
Run Apt-get install-y git
run git config--global user.name "xiangbin Han"
run git config--global user.email "yo Uremail@mydomain.com "
run mkdir/home/myname/.ssh/
run chmod 700/home/myname/.ssh/
ADD id_rsa/home/ myname/.ssh/
run chmod 600/home/myname/.ssh/id_rsa
run echo ' stricthostkeychecking no\nuserknownhostsfile/ Dev/null ' >/home/myname/.ssh/config
run chmod 644/home/myname/.ssh/config
run su-myname-c \
"git Clone ssh://myname@gerrit.server.com:29418/myparent/myproject/home/myname/myproject \
; cd/home/myname/ MyProject \
git fetch ssh://myname@gerrit.server.com:29418/myparent/myproject ${refs} \
git checkout Fetch_head "
RUN chown-r myname:mygroup/home/myname
2) Second, start the container based on the container image file of the build
Docker run-it--name Container_name image_name:version
3) When you need to update a directory or file in a running container, perform the following Docker command Docker exec
Docker exec container_name bash-c "Cd/home/myname/myproject;git fetch ssh://myname@gerrit.server.com:29418/myparent/ MyProject ${gerrit_refspec};git Checkout Fetch_head "
Note that the disadvantage of this approach is that you must be able to execute GIT commands inside the container, and therefore have to add the private key to the container, resulting in a security risk.
2. Execute the Docker CP command directly on the container instance to update the directories and files in the container (recommended)
Docker CP ~/myproject/. Container_name:/home/myname/myproject
3. When you start the container instance, load volume for the container (recommended)
Docker run-v/mnt/temp/myproject/:/home/myname/myproject ...
Additional notes:
In a production environment, because the code is stable, the code can be added directly to the mirror when the image is built.
That is, set the following in Dockfile:
RUN COPY. /home/myname/myproject