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

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

什么是容器?


当前回答

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

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

其他回答

Dockerfile→(Build)→Image→(Run)→Container。

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

简单地说,如果一个图像是一个类,那么容器就是一个类的实例,一个运行时对象。

工作流

下面是端到端的工作流,显示各种命令及其相关的输入和输出。这应该澄清了映像和容器之间的关系。

+------------+  docker build   +--------------+  docker run -dt   +-----------+  docker exec -it   +------+
| Dockerfile | --------------> |    Image     | --------------->  | Container | -----------------> | Bash |
+------------+                 +--------------+                   +-----------+                    +------+
                                 ^
                                 | docker pull
                                 |
                               +--------------+
                               |   Registry   |
                               +--------------+

要列出你可以运行的图像,执行:

docker image ls

列出你可以执行命令的容器:

docker ps

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

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.