Cannot list out stopped container using docker ps -a

8/8/2020

I tried to remove a image using docker rmi image_id and terminal output Error response from daemon: conflict: unable to delete dd85c346890b (must be forced) - image is being used by stopped container b91e905c2b8e. Then I tried to list out the container using docker ps -a but it does not shown. Then I tried docker inspect b91e905c2b8e it does exists. And I can remove the container using docker rm b91e905c2b8e.<br>

Why the container is not shown using docker ps -a. The container is created using kubectl apply pod_config.yaml. Will this affect docker?

Edited:<br> pod.yaml

apiVersion: v1 
kind: Pod 
metadata: 
  name: my-pod
  labels: 
    component: web
spec: 
  containers: 
    - name: client 
      image: imageB // original is imageA    
      ports: 
        - containerPort: 3000
-- HKIT
docker
kubectl
kubernetes

1 Answer

8/27/2020

Quick solution:

docker --host unix:///$HOME/Library/Containers/com.docker.docker/Data/docker.raw.sock ps -a

Explanation:

It seems to be an expected behavior from Docker developers point of view.
Mac version of Docker is using specific socket to connect docker-cli to the daemon that runs on Hyperkit VM.

It works in exactly the same way if you are using docker binary shipped with Docker.app or installed separately.

Luckily Docker-desktop for MacOS creates two kind of sockets:

A "filtered" socket ( used by default ) for the purpose of Docker-desktop application requirements, probably related to its Kubernetes implementation:

$HOME/Library/Containers/com.docker.docker/Data/docker.sock

and the unfiltered one:

$HOME/Library/Containers/com.docker.docker/Data/docker.raw.sock

To show the differences, I've reproduced your situation and got the container with ID: b2f1fed9c793 in Exited state:

$ docker inspect b2f1fed9c793 | grep Status
            "Status": "exited",

$ docker  ps -a | grep b2f1fed9c793
# empty output

When I run the same command connecting to the different sockets I'm getting different results and only raw socket shows exited containers:

$ docker --host unix:///$HOME/Library/Containers/com.docker.docker/Data/docker.sock ps -a | grep b2f1fed9c793
# empty output

$ docker --host unix:///$HOME/Library/Containers/com.docker.docker/Data/docker.raw.sock ps -a | grep b2f1fed9c793
b2f1fed9c793        nginx                              "nginx -g 'daemon of…"   40 minutes ago      Exited (0) 39 minutes ago                            k8s_nginx_nginx3_default_2a5ed89d-ccff-4561-a320-676603d30619_4

Default socket gives 0 lines with Exited containers:

$ docker --host unix:///$HOME/Library/Containers/com.docker.docker/Data/docker.sock ps -a | grep Exited | wc -l 
       0

But raw socket gives 22:

$ docker --host unix:///$HOME/Library/Containers/com.docker.docker/Data/docker.raw.sock ps -a | grep Exited | wc -l 
      22

To use the raw socked by default you can create an alias:

$ alias docker="docker --host unix:///$HOME/Library/Containers/com.docker.docker/Data/docker.raw.sock"

$ docker  ps -a | grep Exited | wc -l 
      22

The solution was originally suggested by lalyos in the issue comment, but he was solving slightly different problem.

-- VAS
Source: StackOverflow