Kode_12
Kode_12

Reputation: 4848

Cannot remove Docker Container from Docker Desktop

I'm trying to remove a container on the Docker Desktop applicaiton. (v3.6.0 Mac)

Cannot remove Docker Compose application. Reason: Error invoking remote method 'compose-action': Error: Command failed: docker-compose --file "docker-compose.yaml" --project-name "tos-apps" --project-directory "/Users/kunalojha/Desktop/tos-apps" down time="2021-08-22T18:40:00-05:00" level=warning msg="The "UID" variable is not set. Defaulting to a blank string." time="2021-08-22T18:40:00-05:00" level=warning msg="The "UID" variable is not set. Defaulting to a blank string." services.redis.user must be a string

It seems to throw this message anytime I attempt to close it. I have seen a github issue opened regarding this and closed after a new release, but i'm still facing the same issue. Any thoughts on how to resolve this?

Upvotes: 21

Views: 22129

Answers (3)

Gonçalo Peres
Gonçalo Peres

Reputation: 13622

In this answer, will share two potential solutions, depending on one's goals:

  1. Remove every container

  2. Remove only one container

For my examples, I will be using WSL terminal on Windows. But the approach should be similar in other environments.


Option 1

If the goal is to remove all the containers, then start by stopping all containers using docker stop

docker stop $(docker ps -a -q)

And then remove them with docker rm

docker rm $(docker ps -a -q)

One can use pruning as well, depending on one's goals. See first note below.

See the last two notes for the way to remove all images and volumes.


Option 2

If the goal is to remove one specific container, start by listing all the Docker containers in one's system with

docker ps -a

[Out]:

CONTAINER ID   IMAGE              COMMAND                  CREATED         STATUS                     PORTS     NAMES
5d5e5c233f5e   nginx              "/docker-entrypoint.…"   3 minutes ago   Up 3 minutes               80/tcp    web-server
6f53b6c2a953   mysql:latest       "docker-entrypoint.s…"   20 hours ago    Exited (137) 20 hours ago            mysql-server
35c37fbf1041   redis              "docker-entrypoint.s…"   2 weeks ago     Exited (0) 2 weeks ago              redis-server

Or

docker ps -aq

[Out]:

5d5e5c233f5e
6f53b6c2a953
35c37fbf1041

If the goal is to remove the CONTAINER ID equal to 5d5e5c233f5e, start by stopping it with stop

docker stop 5d5e5c233f5e

Finally, remove the container with rm

docker rm 5d5e5c233f5e

Notes:

  • Docker takes a conservative approach to cleaning up unused objects (often referred to as “garbage collection”), such as images, containers, volumes, and networks: these objects are generally not removed unless you explicitly ask Docker to do so. This can cause Docker to use extra disk space. For each type of object, Docker provides a prune command.

    Read more about prune

  • The most upvoted answer was leading me into a

    Error response from daemon: You cannot remove a running container... Stop the container before attempting removal or force remove

    The error says it all. Before removing a container, one will need to stop it first.

  • Additionally, one can also remove all the images with docker rmi

    docker rmi $(docker images -q)
    
  • And to remove the remove all the volumes that are not being used with docker volume prune

    docker volume prune
    

Upvotes: 5

brijber
brijber

Reputation: 773

This is how I solved an issue similar to this one:

Find the container id using docker ps - docker ps -a will show all containers, docker ps -l the last created container.

Than remove all the containers for the application individually e.g. docker rm c52b93c43544.

Upvotes: 27

xy c
xy c

Reputation: 1

You can try to remove the container or containers in the cmd.exe

Upvotes: -5

Related Questions