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

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

什么是容器?


当前回答

简而言之:

容器是内核中的一个分区(虚拟),它共享一个公共操作系统并运行一个镜像(Docker镜像)。

容器是一个自我维持的应用程序,它将包含包和运行代码所需的所有依赖项。

其他回答

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

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

就像对象是面向对象编程语言中类的实例一样,Docker容器也是Docker映像的实例。

对于一个虚拟的编程类比,你可以认为Docker有一个抽象的ImageFactory,它保存着它们来自存储的ImageFactory。

然后,一旦你想从ImageFactory中创建一个应用程序,你就有了一个新的容器,你可以随心所欲地修改它。DotNetImageFactory将是不可变的,因为它作为一个抽象工厂类,在那里它只交付您想要的实例。

IContainer newDotNetApp = ImageFactory.DotNetImageFactory.CreateNew(appOptions);
newDotNetApp.ChangeDescription("I am making changes on this instance");
newDotNetApp.Run();

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→(Build)→Image→(Run)→Container。

Dockerfile:包含一组Docker指令,以您喜欢的方式配置您的操作系统,并安装/配置所有软件。 图片:编译好的Dockerfile。节省了每次需要运行容器时重新构建Dockerfile的时间。这是一种隐藏供应代码的方法。 容器:虚拟操作系统本身。您可以ssh进入其中并运行任何命令,就像它是一个真实的环境一样。您可以从同一个映像运行1000多个容器。