Docker文件的优点 [英] Advantages of a Dockerfile

查看:116
本文介绍了Docker文件的优点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以创建Docker图像,并将它们全部推送到Hub而不使用Docker文件。为什么有一个Dockerfile有用?它有哪些优点? Dockerfile创建是一个耗时高的过程,只能由人造成。
我想知道基于图像的基于图像和基于Dockerfile的图像之间的主要区别是什么。

解决方案

Dockerfile 用于通过在泊坞窗图像上指定所需的所有步骤来进行自动化。


Dockerfile是一个文本文档,其中包含用户
可以在命令行上调用以组合图像的所有命令。使用docker
构建用户可以创建一个自动构建,可以连续执行几个
命令行指令。


是的,我们可以创建Docker的图像,但是每当我们想要进行任何更改时,您必须手动更改并测试并推送它。



或者如果您使用Dockerfile dockerhub然后它将自动重建并对每个修改进行更改,如果发生错误,则重建将失败。



Dockerfile的优点




  • Dockerfile是自动化的Docker图像的脚本

  • 当您想要在不同的操作系统风格上测试相同的设置时,手动图像创建将变得复杂,因此您必须创建图像以获得所有风​​格,但是可以通过在Docker文件中进行小的更改图像具有不同的风格

  • 它具有简单的图像语法,并且自动执行许多更改,这将在手动执行时花费更多时间。

  • Dockerfile具有系统的步骤其他人可以轻松了解哪些准确配置在基础图像中更改。



Dockerfile与dockerhub的优势




  • Docker Hub为Dockerfile提供私有存储库。

  • Dockerfile可以在团队和组织之间共享。

  • 自动映像构建

  • 附加到您的存储库的Webhooks,当您将映像或更新的映像推送到存储库时,您可以触发事件

  • 我们可以将Dockerfile放在 Github Bitbucket



承诺图像和Dockerfile图像之间的区别



提交的图像:它将容器的文件更改或设置提交到一个新的图像。

 用法:docker commit [OPTIONS] CONTAINER [REPOSITORY [:TAG]] 
创建一个新的来自容器更改的图像

-a,--author =作者(例如,John Hannibal Smith< hannibal@a-team.com>)
-c,--change = []将Dockerfile指令应用到创建的图像
--help = false打印使用
-m,--message =提交消息
-p,--pause = true提交期间暂停容器

调试容器并将更改的设置导出到另一个图像是很好的选择。但是docker建议使用dockerfile <一个href =https://docs.docker.com/reference/commandline/commit/ =nofollow>看到这里,或者我们可以说commit是docker的版本控制或image的备份。


提交操作不会包含装入容器内的卷
中的任何数据。



默认情况下,正在提交的容器及其进程将在图像提交时暂停
。这样可以减少
在创建
提交过程中遇到数据损坏的可能性。如果此行为是不需要的,请将'p'选项设置为false。


基于Dockerfile的图像: / p>

它始终使用基本图像创建新图像。假设如果您对dockerfile进行了任何更改,那么它将对新鲜图像应用所有docker文件步骤,并创建新的图像。但是提交使用相同的图像。



我的观点我们必须使用我们想要的图像上的所有步骤的dockerfile,但是如果我们从提交创建图像,那么我们必须记录我们所做的所有改变,如果我们想要创建新的图像可能需要,我们可以说dockerfile是图像的文档。


We can create Docker images and all push them to Hub without a Dockerfile. Why is it useful, to have a Dockerfile? What are advantages of it? Dockerfile creation is a process with high consumption of time and can made only by a human. I would like to know what is the main difference between a base image based, committed image and a Dockerfile based image.

解决方案

Dockerfile is used for automation of work by specifying all step that we want on docker image.

A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.

yes , we can create Docker images but every time when we want to make any change then you have to change manually and test and push it .

or if you use Dockerfile with dockerhub then it will rebuild automatically and make change on every modification and if something wrong then rebuild will fail.

Advantages of Dockerfile

  • Dockerfile is automated script of Docker images
  • manual image creation will become complicated when you want to test same setup on different OS flavor then you have to create image for all flavor but by small changing in dockerfile you can create images for different flavor
  • it have simple syntax for image and do many change automatically that will take more time while doing manually.
  • Dockerfile have systematic step that can be understand by others easily and easy to know what exact configuration changed in base image.

Advantage of Dockerfile with dockerhub

  • Docker Hub provide private repository for Dockerfile.
  • Dockerfile can share among team and organization.
  • Automatic image builds
  • Webhooks that are attached to your repositories that allow you to trigger an event when an image or updated image is pushed to the repository
  • we can put Dockerfile on Github or Bitbucket

Difference between committed image and Dockerfile image

Committed image : it commit a container’s file changes or settings into a new image.

Usage:  docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Create a new image from a container's changes

  -a, --author=       Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
  -c, --change=[]     Apply Dockerfile instruction to the created image
  --help=false        Print usage
  -m, --message=      Commit message
  -p, --pause=true    Pause container during commit

It is good option to debug container and export changed setting into another image.but docker suggest to use dockerfile see here or we can say commit is versioning of docker or backup of image.

The commit operation will not include any data contained in volumes mounted inside the container.

By default, the container being committed and its processes will be paused while the image is committed. This reduces the likelihood of encountering data corruption during the process of creating the commit. If this behavior is undesired, set the ‘p’ option to false.

Dockerfile based image:

it always use base image for creating new image. let suppose if you made any change in dockerfile then it will apply all dockerfile steps on fresh image and create new image. but commit use same image.

my point of view we have to use dockerfile that have all step that we want on image but if we create image from commit then we have to document all change that we made that may be needed if we want to create new image and we can say dockerfile is a documentation of image.

这篇关于Docker文件的优点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆