Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't stop and remove docker containers

Tags:

docker

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).

like image 619
Dherik Avatar asked Jan 02 '23 19:01

Dherik


2 Answers

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.

like image 63
Henry Avatar answered Jan 05 '23 18:01

Henry


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)
like image 32
C. Doe Avatar answered Jan 05 '23 19:01

C. Doe