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

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

什么是容器?


当前回答

简而言之:

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

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

其他回答

虽然将容器看作一个运行的映像是最简单的,但这并不十分准确。

An image is really a template that can be turned into a container. To turn an image into a container, the Docker engine takes the image, adds a read-write filesystem on top and initialises various settings including network ports, container name, ID and resource limits. A running container has a currently executing process, but a container can also be stopped (or exited in Docker's terminology). An exited container is not the same as an image, as it can be restarted and will retain its settings and any filesystem changes.

A docker image or a container image in general is a software package which wraps your application executable, dependencies, configurations and application runtime into a secure and immutable unit. When I am saying application executable it differs from application to application. For example if it is a java application it would a jar file, for node application may be a js file. Similarly the application runtime depends on your application itself. For java application it will be JRE, for node application it is node binaries.

您可以根据映像清单文件中提供的说明构建映像。Dockerfile)。构建映像后,可以将其存储在本地或一些容器映像存储库(如hub.docker.com)中。

当您希望将映像作为应用程序工作负载运行时,您可以启动一个需要映像的容器。容器是映像的运行时实例。

要构建一个映像,存储它并将其作为容器运行,你需要一个名为容器运行时的软件,比如Docker。这些容器运行时符合Open container Initiative为映像创建和容器运行提供的标准。

映像是构建容器(正在运行的实例)的蓝图。

简而言之:

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

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

将映像看作容器的“快照”可能会有所帮助。

你可以从容器中创建映像(新的“快照”),也可以从映像中启动新的容器(实例化“快照”)。例如,您可以从一个基本映像实例化一个新容器,在容器中运行一些命令,然后将其“快照”为一个新映像。然后,您可以从这个新映像实例化100个容器。

其他需要考虑的事情:

图像是由层组成的,层是快照“差别”;当你推送一个图像时,只有“diff”被发送到注册表。 Dockerfile在基本映像之上定义了一些命令,这些命令可以创建新的层(“diffs”),从而生成新的映像(“snapshot”)。 容器总是从映像实例化。 图像标签不仅仅是标签。它们是图像的“全名”(“repository:tag”)。如果同一个映像有多个名称,则在处理docker映像时显示多次。