简体   繁体   English

Docker Git克隆在容器启动时启动?

[英]Docker git clone on container launch?

My current understanding is that Docker executes any RUN git clone commands during docker build and thus the codebase for my app is 'baked in' to the Docker image. 我目前的理解是,Docker在Docker docker build过程中执行任何RUN git clone命令,因此我的应用程序的代码库已“嵌入”到Docker映像中。

How would I go about running the git clone when the container launches? 当容器启动时,我将如何运行git clone

Or is this considered bad practice and anti-pattern? 还是这被认为是不良做法和反模式?

The idea being that I don't want to have to uptick my Docker image version every time I make any changes to my git repo. 我的想法是,我不想在每次对git repo进行任何更改时都必须更新Docker映像版本。

The common design pattern is clonning and compiling your project in the Docker image build process. 常见的设计模式是在Docker映像构建过程中克隆和编译您的项目。 In addition, you can configure your image as a Docker Automated Build , which is defined in Docker documentation as: 另外,您可以将映像配置为Docker自动构建 ,在Docker文档中定义为:

Automated Builds are a special feature of Docker Hub which allow you to use Docker Hub's build clusters to automatically create images from a specified Dockerfile and a GitHub or Bitbucket repo (or "context"). 自动构建是Docker Hub的一项特殊功能,可让您使用Docker Hub的构建集群从指定的Dockerfile和GitHub或Bitbucket存储库(或“上下文”)自动创建映像。 The system will clone your repository and build the image described by the Dockerfile using the repository as the context. 系统将克隆您的存储库,并使用该存储库作为上下文构建Dockerfile描述的映像。 The resulting automated image will then be uploaded to the Docker Hub registry and marked as an Automated Build. 然后将生成的自动化映像上传到Docker Hub注册表并标记为“自动生成”。

The automated build is launch anytime you do a commit (and a push) in the branch of the repo you are pointing. 每当您在所指向的存储库分支中进行提交(和推送)时,便会启动自动构建。 If it is triggered too often maybe you should point to other branch. 如果触发太多,也许您应该指向其他分支。

Anyway, if you choose to run the git clone when you run a new container, you can configure your Dockerfile with CMD ["my-script"] , being my-script any bash script with the code you wish. 无论如何,如果您选择在运行新容器时运行git clone,则可以使用CMD ["my-script"]配置Dockerfile,将其作为my-script包含所需代码的任何bash脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM