使用Docker镜像重新启动最新的git代码的最佳方式?

在每个Docker镜像构build之间,唯一改变的就是源代码。 现在,我每次重build图像,然后推送到服务器。 这个操作需要时间。

更新服务器上的代码的最佳做法是什么? 每当Docker重新启动时,我正在考虑运行一些命令,如下所示:

RUN git clone git@bitbucket.org/{user}/{repo} 

这是一个很好的做法吗? 源代码将在主机上; 这是安全的吗?

这是我目前的Docker文件:

 FROM ubuntu:latest RUN apt-get update RUN apt-get install -y nodejs npm git RUN npm install -g bower RUN ln /usr/bin/nodejs /usr/bin/node # Add the current working folder as a mapped folder ADD app.js /opt/myapp/app.js ADD dist /opt/myapp/dist ADD package.json /opt/myapp/package.json ADD bower.json /opt/myapp/bower.json # Set the current working directory to the new mapped folder. WORKDIR /opt/myapp # Install dependencies RUN npm install RUN bower install --allow-root --config.interactive=false # Expose the node.js port to the Docker host. EXPOSE 3005 # This is the stock express binary to start the app. CMD [ "node", "app.js"] 

最近我有一个很好的做法,因为我上个星期做了一个docker:在github上托pipe的源代码,testing使用CircleCI,在DockerHub上自动构build,在Tutum.co上自动部署,最后由我自己的服务器运行(其中一些我从来没有login)

每次我将代码推送到github,github都会通过webhook发送通知给Tutum。 那么Tutum将获得源代码,开始构build并testing我的新Docker镜像。 如果testing通过,图像将被推送到我的私人registry。 那么tutum将发送重新部署通知给我的docker服务,我的docker将拉动新的图像,终止旧的容器,重新启动新的容器与我最新的形象。

以上都是完全自动的。 我运行“git push”命令后,所有事情都会发生。

我个人使用tutum非常沉重,所以我build议你阅读一篇Tutum自动编译的文章: https : //support.tutum.co/support/solutions/articles/5000638474-automated-builds

另外,你可以看看我的docker工人,我用这个小小的玩具项目(CI / CD)find了所有我能find的东西。 🙂 https://github.com/zixia/docker-simple-mail-forwarder