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

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

什么是容器?


当前回答

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

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

其他回答

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.

映像的实例称为容器。你有一个图像,它是你描述的一组图层。如果启动这个映像,就有了这个映像的运行容器。同一个映像可以有多个正在运行的容器。

你可以用docker images看到你所有的图像,而你可以用docker ps看到你正在运行的容器(你可以用docker ps -a看到所有的容器)。

因此,映像的运行实例就是一个容器。

An image is like a class and container is like an object that class and so you can have an infinite number of containers behaving like the image. A class is a blueprint which isnt doing anything on its own. You have to create instances of the object un your program to do anything meaningful. And so is the case with an image and a container. You define your image and then create containers running that image. It isnt exactly similar because object is an instance of a class whereas a container is something like an empty hollow place and you use the image to build up a running host with exactly what the image says

我想用以下类比来说明:

+-----------------------------+-------+-----------+
|             Domain          | Meta  | Concrete  |
+-----------------------------+-------+-----------+
| Docker                      | Image | Container |
| Object oriented programming | Class | Object    |
+-----------------------------+-------+-----------+

在编程方面,

图片是源代码。

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

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