在实践中我开始一个容器:
docker run a8asd8f9asdf0
Run Code Online (Sandbox Code Playgroud)
如果是这样的话,那会是什么:
docker start
Run Code Online (Sandbox Code Playgroud)
做?
在手册中说
启动一个或多个已停止的容器
dan*_*004 289
这是一个非常重要的问题,答案非常简单,但基本:
docker run IMAGE_ID
而不是 docker run CONTAINER_ID
docker stop CONTAINER_ID
可以使用该命令重新启动同一容器docker start CONTAINER_ID
,并且数据和设置将相同.Von*_*onC 95
run
运行图像start
开始一个容器.该docker run
文件确实提到:
该
docker run
命令首先在指定的图像上创建一个可写容器层,然后使用指定的命令启动它.也就是说,码头工人跑相当于API
/containers/create
,然后/containers/(id)/start
.
你没有运行现有的容器,你可以使用docker exec(因为docker 1.3).
您可以重新启动已退出的容器.
y.s*_*hyk 16
run
command creates a container from the image and then starts the root process on this container. Running it with run --rm
flag would save you the trouble of removing the useless dead container afterward and would allow you to ignore the existence of docker start
and docker remove
altogether.
run
command does a few different things:
docker run --name dname image_name bash -c "whoami"
Run Code Online (Sandbox Code Playgroud)
docker ps
bash -c "whoami"
. If one runs docker run --name dname image_name
without a command to execute container would go into stopped state immediately. docker remove
before launching container under the same name.How to remove container once it is stopped automatically? Add an --rm
flag to run
command:
docker run --rm --name dname image_name bash -c "whoami"
Run Code Online (Sandbox Code Playgroud)
How to execute multiple commands in a single container? By preventing that root process from dying. This can be done by running some useless command at start with --detached
flag and then using "execute" to run actual commands:
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'"
Run Code Online (Sandbox Code Playgroud)
Why do we need docker stop
then? To stop this lingering container that we launched in the previous snippet with the endless command tail -f /dev/null
.
小智 15
用例子说明:
假设您的计算机中有游戏(iso)图像.
当您run
(将图像作为虚拟驱动器安装)时,将创建一个虚拟驱动器,其中包含虚拟驱动器中的所有游戏内容,并自动启动游戏安装文件.[运行您的泊坞窗图像 - 创建容器然后启动它.]
但是当你stop
(类似于docker stop)它时,虚拟驱动器仍然存在但停止所有进程.[由于容器存在,直到它不被删除]
当你这样做start
(类似于docker start)时,从虚拟驱动器开始执行游戏文件.[启动现有容器]
在此示例中 - 游戏图像是您的Docker镜像,虚拟驱动器是您的容器.
daniele3004的答案已经很不错了。
只是一个快速和肮脏的公式我这样的人谁混淆了run
,并start
时不时:
docker run [...]
= docker pull [...]
+docker start [...]
归档时间: |
|
查看次数: |
84665 次 |
最近记录: |