docker ps shows empty list
Asked Answered
B

9

92

I built a docker image from a docker file. Build said it succeeded. But when I try to show docker containers through docker ps (also tried docker ps -a), it shows an empty list. What is weird is that I'm still able to somehow push my docker image to dockerhub by calling docker push "container name".

I wonder what's going on? I'm on Windows 7, and just installed the newest version of dockertoolbox.

Battles answered 15/3, 2016 at 14:56 Comment(1)
Same problem Ubuntu22 Docker cant show nvidia-docker containersMoersch
I
147

docker ps shows (running) containers. docker images shows images.

A successfully build docker image should appear in the list which docker images generates. But only a running container (which is an instance of an image) will appear in the list from docker ps (use docker ps -a to also see stopped containers). To start a container from your image, use docker run.

Incurable answered 15/3, 2016 at 14:58 Comment(6)
Just want to make this answer more complete for those docker beginners , command docker ps -a will list all the containers including the Exited and Dead containers.Fredericfrederica
@Fredericfrederica this is extremely helpful. I'm troubleshooting docker for the first time and my container keeps exiting. I couldn't see it without the -a flag.Antithesis
It is very poor design of docker that one needs to add -a . Super noobie unfriendly . I have about 15 containers that I could not find at all.Voltammeter
On my machine, docker ps -al returns only one container, however docker ps -a -f status=exited returns all my containers.Homocercal
@AdrienPacifico the -l flag you used instructs docker to only show the latest created container. If you omit the -l (i.e. docker ps -a) you should get all containers. The -f status=exited filters by status and excludes for example containers in status "Created" or "Dead".Incurable
Oops, I assumed that l standed for "list "as in ls and not latest. @SvenKoschnicke, thank you very much for making me realize that! BestHomocercal
D
42

For me, docker ps -a and docker images both returned an empty list even tho I had many docker containers running. I tried rebooting system with no luck. A quick sudo systemctl restart docker fixed this "bug".

Dremadremann answered 10/6, 2020 at 9:37 Comment(6)
If you have an empty list when you know it shouldn't be empty, this is the right answerDg
This fixed it for me. Every docker command and portainer interface indicated no containers, networks, or really anything except stacks but portainer itself was running so i knew they were executing. Weird..Nephew
This issues is happening to me every time I reboot my ubuntu box. Running sudo systemctl restart docker always fixes it. But it will go bad again on the next reboot. Have in mind the docker containers I should be seeing are indeed running, just docker ps -a does not list them. Docker bug?Grosz
unfortunately this seems to stop all running containers. Is there a way to restart docker "seemlessly"?Stylist
restart docker alone didn't work for me, though it did try to bring my invisible-but-running container again, which of course failed to bind to the port. (Ubuntu Server 22.04LTS if it matters). I think I only needed to do sudo systemctl restart docker.socket after a reboot and it showed the full list again after only a minor blip on the host (not sure if it actually restarts due to the socket restarting).Lovell
Check using snap list if you have docker installe on ubuntu, then remove it with snap remove docker. Snap is an alternate package repository included with ubuntu and some packages overlap with the apt repos.Descartes
B
12

try restarting

sudo systemctl restart docker.socket
sudo systemctl restart docker
Baran answered 16/6, 2022 at 9:2 Comment(2)
This worked for me, I needed to restart docker.socket as well. Thanks.Fortunia
This resolved my issue. After doing a reboot from a firmware update docker.socket needed to be restarted. Interestingly, even though the containers came up as non-existent I could still access the Wiki.js site running from it.Ottoman
M
3

You can run the command with the -D option (for DEBUG mode) so that additional debug information is displayed in the output.

The application might have failed to start.

Mensural answered 16/8, 2021 at 21:52 Comment(0)
L
3

Okay, I think I've found a better root cause for the issue where docker ps shows an empty list, but the containers are known to be running, at least on Ubuntu Server 22.04 where maybe Docker was installed at initial installation (via Snap?) and again later via the standard instructions (via apt).

The answer comes from here: https://forums.docker.com/t/ubuntu-22-04-unexpected-docker-socket-behaviour-after-boot/134626/3

The gist is that Docker is installed from 2 sources: apt + snap, One starts at boot, and the other replaces it (but doesn't know about the running containers).

Check if this is the case by running these commands:

dpkg -l | grep docker
snap list | grep docker

If both show docker then this might be the issue.

Remove the snap install with:

sudo snap remove docker

Once I did the above I received the following output:

$> docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

But then I did:

$> sudo systemctl restart docker.socket
$> docker ps
CONTAINER ID   IMAGE     ...
ffe52...       container ...

And saw my containers.

Also, upon reboot, a simple docker ps shows the expected containers instead of an empty list.

Lovell answered 27/11, 2023 at 8:27 Comment(1)
I got that problem after installing dive through snap. Don't install dive through snapKerianne
A
2

For me, the only thing resolving the issue is to reinstall docker. Also, one must be sure that the disk is not full.

This is the command that I use, but it may vary depending on the version of docker already installed:

apt-get install --reinstall docker.io

If prompted, choose "yes" to automatically restart docker daemon

Ambrosial answered 6/10, 2021 at 6:45 Comment(0)
P
2

for Linux,

at first, see all the running container

sudo docker ps

try restarting

sudo systemctl restart docker

remove previous docker image with the same name if there is any

sudo docker rm docker_container_id

once again run

sudo docker run -d --name container_name image_name

This should work

or uninstall docker and install it again

Pereira answered 6/10, 2021 at 14:7 Comment(0)
S
0

In the Dockerfile instructions, make sure the CMD commands are in between double-quotes not single-qoute

for example:

CMD [ "node" , 'index.js'] Here there is a mistake !!

Correct one is :

CMD [ "node" , "index.js"]

This mistake will make the container run and exit immediately.

Sulphur answered 2/9, 2022 at 8:27 Comment(0)
H
0

In my case I had Dive-in extension installed on Docker Desktop, which I suppose had its own image, and the container was running somewhere. When trying to delete that image it would complain that the container was still running, however, the list of containers was empty.

Since I was not using it anymore, I uninstalled the extension and the image was gone.

Hallway answered 10/8, 2023 at 9:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.