How do I stop a docker container so it will rerun

2019-07-30 06:57发布

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

docker run --name regsvc my-registrationservice

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 Matt

标签: docker
2条回答
放荡不羁爱自由
2楼-- · 2019-07-30 07:40

When you stop a container, you can still see it with:

docker ps -a

Now the container is not alive but it is still there. So, you only need to restart it if you want it to work again:

docker restart regsvc

The command docker run will create a container from your image. So if you want to use docker run again, you need firstly remove your container (after stop it):

docker rm regsvc
docker run --name regsvc my-registrationservice 
查看更多
够拽才男人
3楼-- · 2019-07-30 07:43

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.

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

docker restart regsvc
查看更多
登录 后发表回答