在使用Docker时,我们从一个基本映像开始。我们启动它,创建更改,这些更改被保存在图层中形成另一个图像。

因此,最终我为我的PostgreSQL实例和我的web应用程序提供了一个图像,对这些图像的更改将持续保存。

什么是容器?


当前回答

I would like to fill the missing part here between docker images and containers. Docker uses a union file system (UFS) for containers, which allows multiple filesystems to be mounted in a hierarchy and to appear as a single filesystem. The filesystem from the image has been mounted as a read-only layer, and any changes to the running container are made to a read-write layer mounted on top of this. Because of this, Docker only has to look at the topmost read-write layer to find the changes made to the running system.

其他回答

Dockerfile类似于生成tarball (Docker映像)的Bash脚本。

Docker容器就像tarball的提取版本。您可以在不同的文件夹(容器)中拥有尽可能多的副本。

Image相当于OOP中的类定义,层是该类的不同方法和属性。

容器是图像的实际实例化,就像对象是实例化或类的实例一样。

Docker的核心概念是使创建“机器”变得容易,在这种情况下,机器可以被认为是容器。容器有助于重用性,允许您轻松地创建和删除容器。

图像描述了容器在每个时间点上的状态。所以基本的工作流程是:

创建映像 启动容器 对容器进行更改 将容器重新保存为图像

在编程方面,

图片是源代码。

当编译和构建源代码时,它被称为应用程序。

类似于“当为映像创建实例时”,它被称为“容器”。

也许解释一下整个工作流程会有帮助。

一切都从Dockerfile开始。Dockerfile是映像的源代码。

创建Dockerfile之后,构建它来创建容器的映像。图像只是Dockerfile“源代码”的“编译版本”。

一旦有了容器的映像,就应该使用注册表重新分发它。注册表类似于Git存储库——您可以推送和拉出图像。

接下来,您可以使用映像来运行容器。在许多方面,运行中的容器与虚拟机非常相似(但没有管理程序)。