如何停止Docker容器,以便使用同一命令重新运行该容器? [英] How do I stop a docker container so it will rerun with the same command?

查看:51
本文介绍了如何停止Docker容器,以便使用同一命令重新运行该容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个名字启动我的docker容器.像这样:

I start my docker container with a name. like this:

docker run --name regsvc my-registrationservice

如果我调用docker stop regsvc,则下次我运行上述命令时,它将失败.我必须先运行这些命令.

If I call docker stop regsvc, the next time I run the above command it fails. I have to run these commands first.

docker kill regsvc
docker system prune

那似乎太过分了.有没有更好的方法来停止容器并重新启动它?

That seems excessive. Is there a better way to stop the container and restart it?

Thnx马特

推荐答案

我相信您希望在每次发布 docker run 时都运行一个新容器,对您来说,使用-rm 标志:

I believe you want to run a new container every time you issue docker run and it would be better for you to use --rm flag:

docker run --rm --name regsvc my-registrationservice

这将在容器退出时删除容器.如果您不想保存容器的数据,这会更好.

This will remove the container when your container exits. This is better if you don't want to save data of container.

如@ trong-lam-phan所建议,您可以使用

As suggested by @trong-lam-phan you could restart your existing container using

docker restart regsvc

这篇关于如何停止Docker容器,以便使用同一命令重新运行该容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆