Home » Linux » Applications » Virtualization » Docker List Containers

How to List Containers in Docker (ls Command)

Docker is a virtualization platform that runs on Linux. It allows you to manage and run virtual machines in containers from pre-built images that contain all of the configurations for the virtualized environment.

This tutorial will show you how to list containers using the ls command, part of the new docker command structure.

The ls command replaces the old ps command. The ps command will still work, but you should phase out using it.

Syntax

docker container ls [options]

Docker versions older than 1.13 use the old ps command:

docker ps [options]

Options

Both ls and ps accept the same command options:

Name Shorthand Description
–all -a Show all containers (default shows just running)
–filter -f Filter output based on conditions provided
–format Pretty-print containers using a Go template
–last -n Show n last created containers (includes all states, defaults to -1)
–latest -l Show the latest created container (includes all states)
–no-trunc Don’t truncate output
–quiet -q Only display container IDs
–size -s Display total file sizes

Examples

Here are some examples of how the Docker ls command can be used from the Linux shell:

List Only Running Containers

docker container ls

List All Containers (Running and Stopped)

docker container ls –a

List All Containers By ID

docker container ls –aq

List All Containers Showing File Size

docker container ls –as

List Latest Created Containers

docker container ls –l

List Last 2 Created Containers

docker container ls -n=2

Results

The above ls command examples will return the following details about your containers and print them in your console:

Container ID Unique ID for each container
Image Image the container is based on
Command Command used to launch the container
Created When the container was created
Status The running status of the container – uptime or downtime
Ports Network ports forwarded to the container
Name The name of the container as assigned by Docker

Here’s a rundown on installing and running Docker on Ubuntu 20.04.

Check out our other virtualization tutorials for Docker and Linux here.

SHARE:
Photo of author
Author
I'm Brad, and I'm nearing 20 years of experience with Linux. I've worked in just about every IT role there is before taking the leap into software development. Currently, I'm building desktop and web-based solutions with NodeJS and PHP hosted on Linux infrastructure. Visit my blog or find me on Twitter to see what I'm up to.

Leave a Comment