Dockerfile 的优点 [英] Advantages of a Dockerfile

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

问题描述

我们可以创建 Docker 镜像并将它们全部推送到 Hub 而无需 Dockerfile.为什么有一个 Dockerfile 有用?它有什么优点?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 用于通过在 docker 镜像上指定我们想要的所有步骤来实现工作自动化.

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

Dockerfile 是一个包含用户所有命令的文本文档可以调用命令行来组装图像.使用泊坞窗构建用户可以创建一个自动构建,执行多个命令行指令依次进行.

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.

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

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 .

或者,如果您将 Dockerfile 与 dockerhub 一起使用,那么它将自动重建并在每次修改时进行更改,如果出现问题,则重建将失败.

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.

Dockerfile 的优势

  • Dockerfile 是 Docker 镜像的自动化脚本
  • 当您想在不同的操作系统风格上测试相同的设置时,手动创建映像会变得复杂,然后您必须为所有风格创建映像,但通过在 dockerfile 中进行小的更改,您可以创建不同风格的映像
  • 它具有简单的图像语法,并且可以自动进行许多更改,而手动更改则需要更多时间.
  • Dockerfile 有系统的步骤,其他人可以很容易地理解,并且很容易知道基础镜像中的确切配置发生了什么变化.

Dockerfile 与 dockerhub 的优势

  • Docker Hub 为 Dockerfile 提供私有存储库.
  • Dockerfile 可以在团队和组织之间共享.
  • 自动图像构建
  • 附加到存储库的 Webhook,允许您在将图像或更新的图像推送到存储库时触发事件
  • 我们可以把 Dockerfile 放到 Github 或者 Bitbucket

提交的镜像和 Dockerfile 镜像的区别

提交的映像:它将容器的文件更改或设置提交到新映像中.

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

调试容器并将更改的设置导出到另一个图像是一个不错的选择.但是 docker 建议使用 dockerfile 看这里 或者我们可以说提交是 docker 的版本控制或图像的备份.

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.

默认情况下,正在提交的容器及其进程将提交图像时暂停.这降低了发生的可能性在创建过程中遇到数据损坏犯罪.如果不希望出现这种行为,请将p"选项设置为 false.

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 的映像:

它总是使用基础图像来创建新图像.假设如果您对 dockerfile 进行了任何更改,那么它将在新图像上应用所有 dockerfile 步骤并创建新图像.但提交使用相同的图像.

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.

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

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.

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

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