76

I am new to Docker, and I would like to list the stopped containers.

With docker ps:

sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Nothing appears, because I restarted the machine and I didn't configure them to start the containers automatically.

So when I try to run a container it says:

sudo docker run -d -p 8080:80 --name=angular_moviemasher  moviemasher/angular-moviemasher
docker: Error response from daemon: Conflict. The name "/angular_moviemasher" is already in use by container b4428b708711c15233f558e70f58cb7800e23c4a6a57534abfa5818912630a37. You have to remove (or rename) that container to be able to reuse that name..
See 'docker run --help'.

So I would like to see which Docker containers are already installed and start them.

In the documentation Docker Cheat Sheet with examples I can only find an example of how to show running containers:

Info of Container

To show running Containers. With -a option, it shows running and stopped Containers.

docker ps

2
  • 1
    Not sure why your quote says "running and stopped" and you mention it only shows running, but docker ps --help can be your friend here and other places. Note you can also do docker rm $(docker ps -a | grep Exit | cut -d ' ' -f 1) to remove all Exited containers -- which will remove the conflicting name error you mention.
    – ldg
    Commented Jul 19, 2016 at 18:37
  • 1
    docker container ls -a Commented May 24, 2019 at 17:43

6 Answers 6

99

Like you said docker ps -a will show stopped and running containers (all the containers). The following command will only show you the stopped containers.

docker ps -a | grep Exit

Now you're able to perform docker logs container-id on your container to see what is going wrong.

0
17

Best way to only show stopped containers is to run the following command:

docker container ls -f status=exited -a
13

Another option not mentioned in the answers above is:

docker container list --all

It was added in Docker 1.13 (January 2017), and seems to be the recommended syntax:

In Docker 1.13, we regrouped every command to sit under the logical object it’s interacting with. For example list and startof containers are now subcommands of docker container and history is a subcommand of docker image.

docker container list
docker container start
docker image history

These changes let us clean up the Docker CLI syntax, improve help text and make Docker simpler to use. The old command syntax is still supported, but we encourage everybody to adopt the new syntax.

8

Well you gave yourself the answer:

Info of Container

To show running Containers. With -a option, it shows running and stopped Containers.

docker ps

So try

sudo docker ps -a
2
  • No, because it shows all containers, with running containers cluttering the list. It's as if someone asked how to search for file(s) in a directory and you told them to just run the tree command and spot it...
    – p0358
    Commented Apr 7, 2022 at 11:57
  • My understanding was that one misunderstood the -a option "In the documentation Docker Cheat Sheet with examples I can only find an example of how to show running containers". "-a" is not about showing only running (which was also emphasized) containers, but to show all of them. BTW: Comments like yours are absolutely not helpful for the overall SO community and is one of the reasons why I significantly reduced my time here. It seems many are here just to foster dispute ...
    – DAXaholic
    Commented Apr 19, 2022 at 5:46
5

If docker ps -a isn't showing anything after a machine restart, try restarting the Docker daemon (happens sometime to me too after a shutdown).

1
  • I dont know how and why but it worked for me! Thanks! Commented Nov 25, 2021 at 10:48
0

Show container id of only stop container

docker ps -a | grep Exited | awk '{print$1}'

Restart stop container only

docker restart $(docker ps -a | grep Exited | awk '{print$1}')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.