何时从 Docker 存储库中提取,何时从 Git 存储库中提取然后构建?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49071356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:04:24  来源:igfitidea点击:

When to pull from Docker repo and when from Git repo and then build?

gitdockerdeployment

提问by Gherman

Suppose I have a machine. It can be a single production server, one of production nodes in a cluster, some kind of staging server, a server or a cluster for testing or a developer workstation. Or something different.

假设我有一台机器。它可以是单个生产服务器、集群中的生产节点之一、某种临时服务器、用于测试的服务器或集群或开发人员工作站。或者不同的东西。

Now I want to deliver app to the machine and run it. I can git pull && docker build. Or I can just docker pull. Or I can git pullto another machine and then scpcode instead. Or I can scpdocker image tar and then docker loadinstead of docker pull.

现在我想将应用程序交付到机器并运行它。我可以git pull && docker build。或者我可以docker pull。或者我可以git pull到另一台机器然后scp编码。或者我可以scpdocker image tar 然后docker load代替docker pull.

Sure, Git and Docker are completely different and often used both at the same time. However both have repositories and both can be used to store and deliver code. Even the commands themselves are called the same: push and pull. Docker even has image tags which resemble commits to some limited extend. Because tags also help keep several versions of the app.

当然,Git 和 Docker 是完全不同的,而且经常同时使用。然而,两者都有存储库,都可用于存储和交付代码。甚至命令本身也被称为相同的:推和拉。Docker 甚至有类似于提交的图像标签,在某些有限的范围内。因为标签还有助于保留应用程序的多个版本。

There is even a tool for delivery of apps in Production completely based on Git. It's Capistrano. Capistrano git pulls the code to anther directory and then redirects a symlink to it in order to deploy.

甚至还有一个完全基于 Git 的用于在生产中交付应用程序的工具。是卡皮斯特拉诺。Capistranogit pull将代码放入 anther 目录,然后将符号链接重定向到该目录以进行部署。

The question is which reasons to consider when deciding whether to git pullor docker pullthe code to deliver it to a machine?

问题是在决定是否将其交付给机器git pulldocker pull将其交付给机器时要考虑哪些原因?

采纳答案by Run CMD

Docker and Git are 2 completely different technologies. Git is a Source Control solution, while in docker you can run apps in docker containers. Think of it a sort of 'new' virtualisation technology. You can use both at the same time hower, no problem.

Docker 和 Git 是两种完全不同的技术。Git 是一种源代码控制解决方案,而在 docker 中,您可以在 docker 容器中运行应用程序。将其视为一种“新”虚拟化技术。您可以同时使用两者,没问题。

.... EDIT ...

.... 编辑 ...

Docker doesn't keep a copy of your source code. With docker you can build an image based on your source code and put that in a repository. From that image you can run an app in a docker container. So as for workflow basically, you just develop using git, and for deployment you use Docker...

Docker 不会保留您的源代码的副本。使用 docker,您可以根据源代码构建映像并将其放入存储库。从该映像中,您可以在 docker 容器中运行应用程序。因此,对于工作流,基本上,您只需使用 git 进行开发,而对于部署,您使用 Docker ......

回答by eli

like the other answers say, git is for version control, e.g. for textfiles.

就像其他答案说的那样,git 用于版本控制,例如用于文本文件。

You build a docker container from a "dockerfile" (which is a textfile). This "dockerfile" is placed in a directory with many other files and folders.

您从“dockerfile”(这是一个文本文件)构建一个 docker 容器。这个“dockerfile”放置在一个包含许多其他文件和文件夹的目录中。

So if you put this directory, where the dockerfile is located in, into a git repository, then everyone who has access to it, can build the same docker container, with the same configurations and everything.

因此,如果您将 dockerfile 所在的这个目录放入 git 存储库,那么每个有权访问它的人都可以构建相同的 docker 容器,具有相同的配置和所有内容。

is that what you mean?

你是这个意思吗?

So, the docker container is a "building" and the DOCKER-repository is a market where you can download already built buildings (images), from that you can run a virtualmachine/container.
And the files in the GIT-repository (this is like a big archive for e.g. documents) are the "construction plans". You "share" the different version of the "construction plans" via git, so everyone can build every version of the building.

因此,docker 容器是一个“建筑物”,而 DOCKER 存储库是一个市场,您可以在其中下载已构建的建筑物(图像),从中您可以运行虚拟机/容器。
并且 GIT 存储库中的文件(这就像一个大档案,例如文档)是“构建计划”。你通过git“共享”不同版本的“建设计划”,所以每个人都可以建造每个版本的建筑。

Example Workflow:

示例工作流:

In your development environment (your local computer):

在您的开发环境(您的本地计算机)中:

  1. git pull- pull the "construction - instructions" from git repository (e.g. dockerfile)
  2. docker build- build the docker image from that dockerfile-instructions
  3. docker push myDockerRepo/myDockerImage:latest- push the newly built docker image into the DOCKER repository (NOT the git-repository)
  1. git pull- 从 git 存储库(例如 dockerfile)中提取“构造 - 说明”
  2. docker build- 从那个 dockerfile-instructions 构建 docker 镜像
  3. docker push myDockerRepo/myDockerImage:latest- 将新构建的 docker 镜像推送到 DOCKER 存储库(不是 git-repository)

In your production environment:

在您的生产环境中:

  1. docker pull myDockerRepo/myDockerImage:latest- pull the latest docker image from the DOCKER-repository
  2. docker run- run a new containerized instance (basically a VirtualMachine) FROM the docker image
  1. docker pull myDockerRepo/myDockerImage:latest- 从 DOCKER-repository 中拉取最新的 docker 镜像
  2. docker run- 从 docker 镜像运行一个新的容器化实例(基本上是一个 VirtualMachine)

回答by Murat Güven?

Docker push command, pushes your images to the docker repository, images is not the source code, although may contain source code, and successive pushes for images can override each other and doesn't provide versioning. It is used for pulling images and running containers. Docker Repo further info

Docker push 命令,将您的图像推送到 docker 存储库,图像不是源代码,尽管可能包含源代码,并且图像的连续推送可以相互覆盖并且不提供版本控制。它用于拉取镜像和运行容器。 Docker Repo 更多信息

On the other hand git push, pushes your source code and other files to the the remote repository. Which is for version controlling. You can pull, fork or pull request to a remote git repository, and can build application from source code. Git Repo further info

另一方面,git push 将您的源代码和其他文件推送到远程存储库。这是用于版本控制的。您可以拉取、分叉或拉取请求到远程 git 存储库,并且可以从源代码构建应用程序。 Git 回购更多信息

They can be used together, and actually is being used together by many developers. They aim to solve different problems.

它们可以一起使用,并且实际上正在被许多开发人员一起使用。他们旨在解决不同的问题。