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

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

什么是容器?


当前回答

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

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中,镜像是一个不可变的文件,它包含docker应用程序运行所需的源代码和信息。它可以独立于容器而存在。

Docker容器是在运行时创建的虚拟化环境,需要镜像才能运行。docker网站上有一张图片显示了这种关系:

长话短说。

码头工人图片:

用于创建容器的文件系统和配置(只读)应用程序。

码头工人的容器:

容器和映像之间的主要区别是最上面的可写层。容器是顶层可写层的Docker映像的运行实例。容器运行实际的应用程序。容器包括应用程序及其所有依赖项。当容器被删除时,可写层也会被删除。底层图像保持不变。


其他需要注意的重要术语:

码头工人守护进程:

运行在主机上的后台服务,它管理构建,运行和分发Docker容器。

码头工人客户:

允许用户与Docker守护进程交互的命令行工具。

码头工人商店:

Store是一个Docker映像的注册表。您可以将注册表视为所有可用Docker映像的目录

这篇博文中的一张图片胜过千言万语。

简介:

从Docker中心提取图像或从Dockerfile构建=>给出一个 Docker图像(不可编辑)。 运行image (docker Run image_name:tag_name) =>给出一个运行 图片即容器(可编辑)

简而言之:

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

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

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

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

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