Dherik
Dherik

Reputation: 19120

Can't stop and remove docker containers

I'm trying to stop and remove some docker containers on my machine, but something really weird is happening here.

I tried to stop:

docker stop $(docker ps -a -q)

This works for a moment, because the docker ps shows no container running. But few seconds later the images appear again with a new container ID.

I tried to stop (last command) then remove:

docker rm $(docker ps -a -q)

But I received an error:

Error: No such container: 0f57644645eb

I also tried this command on the running containers after repeat the stop command:

docker update --restart=no container-id

The command is successful, but the container are still restarting.

I tried to remove all images after stop them:

docker stop $(docker ps -a -q)
docker rmi $(docker images -q)

But I received another error:

Error response from daemon: conflict: unable to delete 0f57644645eb (cannot be forced) - image is being used by running container dcef9cdb703c

What I'm missing here? I would like to stop and remove these containers to leave Docker as it was after a fresh install.

I'm using Windows 10 and Docker version 17.12.0-ce-win47 (15139).

Upvotes: 4

Views: 16475

Answers (3)

Henry
Henry

Reputation: 43798

The behaviour indicates that the container was started as a service. The service will try to restart in order to fulfil the specification of running instances.

The services can be checked with docker service ls.

It is necessary to remove or reconfigure the service to permanently stop the container.

Upvotes: 5

Gaurav Sharma
Gaurav Sharma

Reputation: 29

This worked for me:

docker rm CONTAINER_ID

Upvotes: 3

C. Doe
C. Doe

Reputation: 1436

Could you just try to use the force flag with your removal commands?

docker rm -f $(docker ps -aq)
docker rmi -f $(docker images -q)

Upvotes: 4

Related Questions