问题描述
我使用以下命令从映像启动docker容器:
I launch a docker container from an image with the following command:
$ docker run -d myimage /bin/bash -c "mycommand"
当 mycommand
完成后,容器停止了(我想它已经停止了),但是没有删除,因为我可以使用以下命令看到它:
When "mycommand"
is finished, the container is stopped (I suppose it is stopped), but it is not deleted, because I can see it with this command:
$ docker ps -a
有没有办法重新启动
具有相同参数的此容器,并保留由 mycommand
?
Is there any way to restart
this container with the same parameters and keep data generated by mycommand
?
推荐答案
是的,当初始命令执行完毕后,容器将停止。
Yes, when the initial command finish its execution then the container stops.
您可以使用以下方法启动已停止的容器:
You can start a stopped container using:
docker start container_name
如果要查看输出您的命令,则应该添加 -ai
选项:
If you want to see the output of your command then you should add -ai
options:
docker start -ai container_name
PS。有一个 docker restart container_name
,但它用于重启正在运行的容器-我相信情况并非如此。
PS. there is a docker restart container_name
but that is used to restart a running container - I believe that is not your case.
这篇关于如何重新启动已停止的Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!