在实践中开始一个容器我做:

docker run a8asd8f9asdf0

如果是这样的话,怎么办:

docker start

do?

手册上写着

启动一个或多个停止的容器


当前回答

举例说明:

假设您的计算机中有一个游戏(iso)映像。

当您运行(将映像挂载为虚拟驱动器)时,将创建一个虚拟驱动器,其中包含虚拟驱动器中的所有游戏内容,并自动启动游戏安装文件。运行你的docker镜像-创建一个容器,然后启动它。

但是当你停止它(类似于docker stop),虚拟驱动器仍然存在,但停止所有进程。[因为容器一直存在直到它被删除]

当你启动时(类似于docker start),游戏文件从虚拟驱动器开始执行。[启动现有容器]

在本例中,游戏映像是Docker映像,虚拟驱动器是容器。

其他回答

运行命令从映像创建一个容器,然后在该容器上启动根进程。使用run——rm标志运行它将为你省去事后删除无用的死容器的麻烦,并允许你完全忽略docker start和docker remove的存在。

Run命令做了一些不同的事情:

docker run --name dname image_name bash -c "whoami"

Creates a Container from the image. At this point container would have an id, might have a name if one is given, will show up in docker ps Starts/executes the root process of the container. In the code above that would execute bash -c "whoami". If one runs docker run --name dname image_name without a command to execute container would go into stopped state immediately. Once the root process is finished, the container is stopped. At this point, it is pretty much useless. One can not execute anything anymore or resurrect the container. There are basically 2 ways out of stopped state: remove the container or create a checkpoint (i.e. an image) out of stopped container to run something else. One has to run docker remove before launching container under the same name.

一旦容器自动停止,如何移除容器?为run命令添加——rm标志:

docker run --rm --name dname image_name bash -c "whoami"

如何在一个容器中执行多个命令?通过防止根突死亡。这可以通过在开始时运行一些无用的命令——detached flag来实现,然后使用"execute"来运行实际的命令:

docker run --rm -d --name dname image_name tail -f /dev/null
docker exec dname bash -c "whoami"
docker exec dname bash -c "echo 'Nnice'"

为什么我们需要码头停车呢?要停止我们在前面的代码段中使用无尽的尾部命令启动的这个滞留容器-f /dev/null.

将命令命名为“new”而不是“run”会更明智。

Run创建一个现有(或可下载)映像的容器实例并启动它。

Daniele3004的答案已经很不错了。

对于像我这样时不时把跑和开始混在一起的人来说,这只是一个快速而肮脏的公式:

Docker run[…= docker pull[…]+ docker start[…]

这是一个非常重要的问题,答案很简单,但却是基本的:

运行:创建镜像的新容器,并执行该容器。您可以创建同一映像的N个克隆。命令如下: docker运行IMAGE_ID,非docker运行CONTAINER_ID

启动:启动先前停止的容器。例如,如果你已经用命令docker stop CONTAINER_ID停止了一个数据库,你可以用命令docker start CONTAINER_ID重新启动同一个容器,数据和设置将是相同的。

举例说明:

假设您的计算机中有一个游戏(iso)映像。

当您运行(将映像挂载为虚拟驱动器)时,将创建一个虚拟驱动器,其中包含虚拟驱动器中的所有游戏内容,并自动启动游戏安装文件。运行你的docker镜像-创建一个容器,然后启动它。

但是当你停止它(类似于docker stop),虚拟驱动器仍然存在,但停止所有进程。[因为容器一直存在直到它被删除]

当你启动时(类似于docker start),游戏文件从虚拟驱动器开始执行。[启动现有容器]

在本例中,游戏映像是Docker映像,虚拟驱动器是容器。