87

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.

CtheGood
  • 999
  • 8
  • 17
Ville Miekk-oja
  • 18,749
  • 32
  • 70
  • 106

8 Answers8

143

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.

Sven Koschnicke
  • 6,523
  • 2
  • 34
  • 49
  • 46
    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. – mainframer Mar 19 '16 at 08:23
  • 4
    @mainframer 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. – Ethan Hohensee Oct 08 '17 at 19:35
  • 1
    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. – WestCoastProjects Oct 15 '19 at 03:17
  • On my machine, `docker ps -al` returns only one container, however `docker ps -a -f status=exited` returns all my containers. – Adrien Pacifico Nov 25 '22 at 07:58
  • @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". – Sven Koschnicke Jan 02 '23 at 14:07
  • Oops, I assumed that `l` standed for "list "as in `ls` and not `latest`. @SvenKoschnicke, thank you very much for making me realize that! Best – Adrien Pacifico Jan 03 '23 at 15:18
37

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

Erol444
  • 615
  • 5
  • 12
  • 3
    If you have an empty list when you know it shouldn't be empty, this is the right answer – Ken Syme Aug 09 '20 at 11:35
  • 2
    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.. – Chris Rice Sep 28 '20 at 22:08
  • 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? – ruralcoder Oct 14 '20 at 17:38
  • unfortunately this seems to stop all running containers. Is there a way to restart docker "seemlessly"? – D M Apr 09 '21 at 09:14
6

try restarting

sudo systemctl restart docker.socket
sudo systemctl restart docker
Blastfurnace
  • 18,411
  • 56
  • 55
  • 70
3

You can run the command without the -d option. So you have the output displayed.

It may be that the application failed to start.

donjoe
  • 31
  • 5
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

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

MD SHAYON
  • 7,001
  • 45
  • 38
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.

Weheid
  • 31
  • 3
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.

gedijedi
  • 596
  • 1
  • 6
  • 7