简体   繁体   English

DockerFile:用于创建映像还是到Docker主机如何创建容器

[英]DockerFile: Is it use to create an image or To the docker host how to create the container

I am confused with some terms. 我对某些术语感到困惑。

Is Dockerile designed to create an image or a set of instruction of how to create a container from an image? Dockerile是设计用来创建映像还是用于从映像创建容器的一组指令?

Because there are command eg FROM (to get the base image), RUN (To run executable in the container) etc. These command looks like an instruction to how to create the container. 因为有命令,例如FROM (获取基本映像), RUN (在容器中运行可执行文件)等。这些命令看起来像是有关如何创建容器的指令。

Docker images are static, and are built from the instructions specified in the Dockerfile . Docker映像是静态的,并且是根据Dockerfile指定的指令Dockerfile They use Union File-System (UnionFS), so that the changes made when building an image are stacked on top of each other, generating a DAG (Directed Acyclic Graph) of build history. 他们使用联合文件系统(UnionFS),以便在构建映像时所做的更改彼此堆叠,从而生成构建历史记录的DAG(有向无环图)。 The FROM directive at the top of the Dockerfile simply points to an existing image, and starts building on top of that. Dockerfile顶部的FROM指令仅指向现有映像,并在此映像之上开始构建。

A container is simply an instantiated version of an image, basically just this UnionFS with a read/write layer dropped on top of it. 容器只是图像的实例化版本,基本上就是这个UnionFS,在其顶部放置了一个读/写层。

Interestingly, if you watch the output when you run docker build (in a directory with a Dockerfile ) you'll see that what is happening is each instruction starts up a container based on the current state of the image, runs the command ( apt-get install ... or whatever) and then commit s that change to the image. 有趣的是,如果您在运行Dockerfile docker build (在带有Dockerfile的目录中)观察输出,您会发现正在发生的事情是每条指令根据映像的当前状态启动一个容器,然后运行命令( apt-get install ...或其他内容),然后commit更改为映像的。 That's why it's good to batch up commands in a Dockerfile - because each one will start a new container. 这就是在Dockerfile批处理命令的好Dockerfile -因为每个命令都会启动一个新容器。

Dockerfile is used to create an image which you can later use to create a container using docker build . Dockerfile被用于创建以后可以使用它来创建使用容器的图像docker build

From the docs 来自文档

Docker can build images automatically by reading the instructions from a Dockerfile. Docker可以通过阅读Dockerfile中的指令来自动构建映像。 A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Dockerfile是一个文本文档,其中包含用户可以在命令行上调用以组装映像的所有命令。 Using docker build users can create an automated build that executes several command-line instructions in succession. 使用docker build的用户可以创建自动执行的构建,该构建可以连续执行几个命令行指令。

Also RUN will instruction will execute any commands in a new layer on top of the current image and commit the results . 同样, RUN will指令将在当前图像顶部的新层中执行任何命令并提交结果 The resulting committed image will be used for the next step in the Dockerfile and not "Run (To run executable in the container)". 生成的提交映像将用于Dockerfile中的Dockerfile而不是“运行(在容器中运行可执行文件)”。 For details see this . 有关详情请参阅

Image: Docker engine use Dockerfile reference to build up Image from Dockerfile instruction like (FROM, RUN etc.) 图像: Docker engine使用Dockerfile引用从Dockerfile指令(例如FROM,RUN等)构建Image

Container: Docker engine start container from Image and we can say Container is RUN time instance of Image 容器: Docker engineImage启动容器,我们可以说ContainerImage运行时间实例

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

相关问题 如何创建与主机用户具有相同文件权限的docker镜像/容器 - how to create a docker image/container with same file rights as host user 为什么 docker 必须从 dockerfile 创建映像,然后从映像创建容器,而不是从 Dockerfile 创建容器? - Why does docker have to create an image from a dockerfile then create a container from the image instead of creating a container from a Dockerfile? 如何在Boot2docker中创建Dockerfile以创建映像 - How to create Dockerfile in Boot2docker to create an image 如何创建一个Dockerfile在Windows 2016容器中运行Docker? - How to Create a Dockerfile to Run Docker in a Windows 2016 Container? 从 NiFi Docker 容器创建一个 Dockerfile - Create a Dockerfile from NiFi Docker Container 如何从 Azure 容器注册表中的映像创建 Dockerfile? - How can I create a Dockerfile FROM an Image in Azure Container Registry? 使用Docker容器创建/删除主机iptable规则 - Use Docker container to create/delete host iptable rules 如何改进我的 Dockerfile 以完美地为 Angular 应用程序创建 Docker 图像? - How to improve my Dockerfile to create an Docker image for Angular application perfectly? 如何使用 Maven 从 dockerfile 创建和运行 docker 镜像 - how to create and run docker image using Maven from dockerfile Dockerfile 与从容器创建映像 - Dockerfile vs create image from container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM