Docker ps -a Explained (List All Containers with Examples & Filters)

Docker ps -a Explained (List All Containers with Examples & Filters)

To list all Docker containers (including stopped ones), use:

text
docker ps -a

This command shows both running and exited containers, helping you manage the full container lifecycle.


Quick Command Reference

TaskCommand
List all containersdocker ps -a
List running containersdocker ps
List stopped containersdocker ps -f "status=exited"
Filter by namedocker ps -a --filter "name=<name>"
Show only container IDsdocker ps -aq

Understanding docker ps vs docker ps -a

Difference between running and stopped containers

  • docker ps shows only running containers
  • docker ps -a shows all containers, including stopped ones
  • Stopped containers can be inspected, restarted, or removed

If you need to restart stopped containers, refer to restart docker container.


Common Ways to Use docker ps -a

Method 1: List all containers (basic usage)

text
docker ps -a

This displays all containers along with their status, names, and IDs. You can then take further actions like stopping or removing containers. For example, you can
stop all docker containers if required.

Method 2: Show only stopped containers

text
docker ps -f "status=exited"

This helps identify containers that have completed execution or failed.

To clean up unused containers, refer to remove unused docker containers.

Method 3: Filter containers by name or status

text
docker ps -a --filter "name=<name>"

You can also filter by status, image, or other parameters to narrow down results.

If you are troubleshooting containers, you may also want to check logs using docker logs.


Understanding docker ps -a Output

Key columns explained (CONTAINER ID, STATUS, NAMES)

  • CONTAINER ID → Unique identifier for each container
  • IMAGE → Docker image used to create the container
  • COMMAND → Command executed when the container started
  • STATUS → Current state (e.g., Up, Exited, Restarting)
  • PORTS → Port mappings between host and container
  • NAMES → Human-readable container name

If a container shows as Exited, it means the main process has stopped. You can inspect logs using docker logs to identify the issue.


Best Practices for Managing Containers

  • Regularly check container status using docker ps -a
  • Remove unused containers to free up resources
  • Use meaningful names for easier identification (see rename docker container)
  • Restart stopped containers when needed (refer to docker restart container)
  • Monitor logs for debugging and performance issues

For better cleanup and resource management, you can also remove unused docker containers.


Frequently Asked Questions

1. What does docker ps -a do?

docker ps -a lists all Docker containers, including running and stopped ones.

2. How is docker ps different from docker ps -a?

docker ps shows only running containers, while docker ps -a shows all containers.

3. Can I filter docker ps -a output?

Yes, you can use filters like status, name, and ancestor to refine the output.

4. Why are some containers shown as exited?

Containers are shown as exited when their main process has completed or stopped.

Conclusion

The docker ps -a command is essential for viewing and managing all containers, including those that are stopped. By understanding its output and using filters effectively, you can improve container visibility and control across your Docker environment.

To perform actions on containers, you may also find it useful to stop all docker containers or keep docker container running depending on your use case.


Official Documentation

For more details, refer to the official Docker documentation:

Docker ps command documentation

Deepak Prasad

Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.