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

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

什么是容器?


当前回答

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

其他回答

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

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

正如许多回答指出的那样:你构建Dockerfile来获取一个图像,然后运行image来获取一个容器。

但是,下面的步骤帮助我更好地了解Docker映像和容器是什么:

1)构建Dockerfile:

Docker build -t my_image dir_with_dockerfile

2)保存镜像到.tar文件

-o my_file.tar my_image_id

My_file.tar将存储映像。使用tar -xvf my_file.tar打开它,您将看到所有的层。如果你深入每一层,你可以看到每一层添加了什么变化。(它们应该非常接近Dockerfile中的命令)。

3)要查看容器内部,您可以:

Sudo docker运行- my_image bash

你可以看到它很像一个操作系统。

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

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.

映像或容器映像是一个包含应用程序代码、应用程序运行时、配置和依赖库的文件。映像基本上是将所有这些包装成一个单一的、安全的不可变单元。使用适当的docker命令构建映像。图像有图像id和图像标签。标签的格式通常为<docker-user-name>/image-name:tag。

当您开始使用映像运行应用程序时,实际上是启动了一个容器。你的容器是一个运行图像的沙盒。Docker软件用于管理映像和容器。

Image是一个安全的包,其中包含应用程序工件、库、配置和应用程序运行时。容器是映像的运行时表示形式。

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