Mastering Docker PS: Your Container Command Center

Docker containers are like lightweight virtual machines running your applications. But how do you keep track of what’s running? Enter docker ps - your essential command for container management.

Basic Usage

The simplest form is just:

docker ps

This shows your running containers with their:

  • Container ID
  • Image name
  • Command running inside
  • Creation time
  • Status
  • Ports
  • Names

Common Options

View All Containers

docker ps -a

Shows both running AND stopped containers. Essential for debugging or cleanup.

Show Container Sizes

docker ps -s

Adds size information to the output. Helpful for monitoring disk usage.

Custom Format

docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}"

Creates a customized view showing only what you need.

Pro Tips

  1. Quick Container ID Copy

    docker ps -q
    

    Shows only container IDs - perfect for scripting.

  2. Filter Your View

    docker ps --filter "status=running" --filter "name=web"
    

    Find specific containers by status, name, or other criteria.

  3. Latest Container

    docker ps -l
    

    Shows only the latest created container.

Troubleshooting Common Issues

  • No Containers Showing? Check if they’re running with docker ps -a
  • Too Much Output? Use formatting to show only needed columns
  • Container Keeps Disappearing? Check logs with docker logs [container-id]

Best Practices

  1. Name your containers using --name when running them
  2. Use meaningful container names for easier identification
  3. Regularly clean up stopped containers with docker container prune
  4. Monitor container resource usage with docker stats

Beyond docker ps

While docker ps is essential, modern Docker also offers:

  • docker container ls (same as docker ps)
  • docker container inspect (detailed container info)
  • docker stats (resource usage)

Remember: docker ps is your first step in container management. Master it, and you’re on your way to becoming a Docker expert!