tatmanblue
tatmanblue

Reputation: 1227

How do I stop a docker container so it will rerun with the same command?

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

Upvotes: 1

Views: 2158

Answers (2)

Ayushya
Ayushya

Reputation: 10447

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

Upvotes: 2

Trong Lam Phan
Trong Lam Phan

Reputation: 2412

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 

Upvotes: 3

Related Questions