简体   繁体   English

Dockerfile与Docker镜像

[英]Dockerfile vs Docker image

I'm working on creating some docker images to be used for testing on dev machines. 我正在创建一些用于在开发机器上进行测试的docker镜像。 I plan to build one for our main app as well as one for each of our external dependencies (postgres, elasticsearch, etc). 我计划为我们的主应用程序构建一个,以及为每个外部依赖项构建一个(postgres,elasticsearch等)。 For the main app, I'm struggling with the decision of writing a Dockerfile or compiling an image to be hosted. 对于主应用程序,我正在努力编写Dockerfile或编译要托管的映像。

On one hand, a Dockerfile is easy to share and modify over time. 一方面,Dockerfile很容易随时间共享和修改。 On the other hand, I expect that advanced configuration (customizing application property files) will be much easier to do in vim before simply committing an new image. 另一方面,我希望在提交新图像之前,在vim中更容易进行高级配置(自定义应用程序属性文件)。

I understand that I can get to the same result either way, but I'm looking for PROS, CONS, and gotchas with either direction. 我知道我可以得到相同的结果,但我正在寻找PROS,CONS和任何方向的问题。

As a side note, I plan on wrapping this all together using Fig . 作为一个方面说明,我计划在所有包装了一起利用 My initial impression of this tool has been very positive. 我对这个工具的初步印象非常积极。

Thanks! 谢谢!

Using a Dockerfile: 使用Dockerfile:

  • You have an 'audit log' that describes how the image is built. 您有一个描述图像构建方式的“审核日志”。 For me this is fundamental if it is going to be used in a production pipeline where more people are working and maintainability should be a priority. 对我而言,如果它将被用于生产管道中,这将是更基本的,因为更多的人正在工作,可维护性应该是一个优先事项。
  • You can automate the building process of your image, being an easy way of updating the container with system updates, or if it has to take part in a continuous delivery pipeline. 您可以自动化图像的构建过程,这是使用系统更新更新容器的简单方法,或者是否必须参与持续交付管道。
  • It is a cleaner way of create the layers of your container (each Dockerfile command is a different layer) 这是一种创建容器层的更简洁方法(每个Dockerfile命令是不同的层)

Changing a container and committing the changes is great for testing purposes and for fast development for a conceptual test. 更改容器并提交更改非常适合测试目的和概念测试的快速开发。 But if you plan to use the result image for some time, I would definitely use Dockerfiles. 但是如果你计划使用结果图像一段时间,我肯定会使用Dockerfiles。

Apart from this, if you have to modify a file and doing it using bash tools (awk, sed...) results very tedious, you can add any file you wish from outside during the building process. 除此之外,如果您必须修改文件并使用bash工具(awk,sed ...)进行操作,结果非常繁琐,您可以在构建过程中从外部添加任何您想要的文件。

I totally agree with Javier but you need to understand that one image created with a dockerfile can be different with an image build with the same version of the dockerfile 1 day after. 我完全同意Javier,但是您需要了解使用dockerfile创建的一个映像可能与使用相同版本的dockerfile的映像构建不同。

maybe in your build process you retrieve automatically last updates of an app or the os etc … 也许在您的构建过程中,您自动检索应用程序或操作系统等的最新更新...

And at this time if you need to reproduce a crash or whatever you can't rely on the dockerfile. 此时如果你需要重现崩溃或任何你不能依赖于dockerfile的东西。

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

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