How to List Containers in Docker

How to List Containers in Docker

All

Linux Articles / All 70 Views comments

Docker is a containerization platform that lets you shortly construct, check, and deploy purposes as moveable, self-sufficient containers that may run nearly anyplace. It's the de-facto normal for container deployment, and it's an important device for DevOps engineers and their steady integration and supply pipeline.

On this article, we'll clarify how one can record Docker containers.

Listing Docker Containers

The Docker command for itemizing containers takes the next type:

docker container ls [options]

Older Docker variations earlier than 1.13 are utilizing a unique command to record the containers:

docker ps [options]

The command above continues to be supported in newer Docker variations the place the ps command is an alias to container ls.

To listing the operating container run the docker container ls command with none choice:

docker container ls

The output will look one thing like this:

CONTAINER ID    IMAGE        COMMAND                  CREATED        STATUS        PORTS       NAMES
c8bded53da86    postgres     "docker-entrypoint.s…"   2 hours in the past    Up 2 hours    5432/tcp    pg
571c3a115fcf    redis        "docker-entrypoint.s…"   four hours in the past    Up four hours    6379/tcp    cache
05ef6d8680ba    nginx        "nginx -g 'daemon of…"   2 hours in the past    Up 2 hours    80/tcp      net

Every line of the output consists of the next columns:

  • Container ID – A singular alphanumeric string that identifies every container.
  • Picture – The Docker picture used to create the container.
  • Command – The command that's executed when beginning the container.
  • Created – The creation time of the container.
  • Standing – The standing of the container.
  • Ports – The container's revealed ports.
  • Identify – The identify of the container.

If there are not any operating containers, solely the header line is displayed.

The -a, --all choice tells docker container ls to print an inventory of all containers:

docker container ls -a
CONTAINER ID    IMAGE        COMMAND                  CREATED        STATUS                    PORTS       NAMES
b28cbaa91f15    couchbase    "/entrypoint.sh couc…"   5 hours in the past    Exited (zero) three hours in the past                db
c8bded53da86    postgres     "docker-entrypoint.s…"   2 hours in the past    Up 2 hours                5432/tcp    pg
571c3a115fcf    redis        "docker-entrypoint.s…"   four hours in the past    Up four hours                6379/tcp    cache
05ef6d8680ba    nginx        "nginx -g 'daemon of…"   2 hours in the past    Up 2 hours                80/tcp      net

By default, columns with a size exceeding a specified restrict are truncated. Use the --no-trunc choice to disable truncation:

docker container ls --no-trunc

To solely show the containers’ IDs move the -q, --quiet choice:

docker container ls -q
c8bded53da86
571c3a115fcf
05ef6d8680ba

The --format permits you to format the output utilizing a Go template. For instance to print solely the containers’ names and standing together with the header you'd run:

docker container ls --format 'desk .Namest.Standing'
NAMES    STATUS
pg       Up 2 hours
cache    Up four hours
net      Up 2 hours

Use the -s, --size choice to view the dimensions of the containers:

docker container ls -s

Every line will embrace a column named SIZE that exhibits the container measurement:

CONTAINER ID    IMAGE        COMMAND                  CREATED        STATUS        PORTS       NAMES    SIZE
c8bded53da86    postgres     "docker-entrypoint.s…"   2 hours in the past    Up 2 hours    5432/tcp    pg       63B (digital 394MB)
571c3a115fcf    redis        "docker-entrypoint.s…"   four hours in the past    Up four hours    6379/tcp    cache    0B (digital 98.2MB)
05ef6d8680ba    nginx        "nginx -g 'daemon of…"   2 hours in the past    Up 2 hours    80/tcp      net      2B (digital 126MB)

The --last, -n choice tells the command to show n final created containers, together with all states. For instance, to view the newest two created containers you'd run:

docker container ls -n 2
CONTAINER ID    IMAGE        COMMAND                  CREATED        STATUS                    PORTS       NAMES
b28cbaa91f15    couchbase    "/entrypoint.sh couc…"   5 hours in the past    Exited (zero) three hours in the past                db
c8bded53da86    postgres     "docker-entrypoint.s…"   2 hours in the past    Up 2 hours                5432/tcp    pg

There's additionally an choice to record solely the newest created container --latest , -l which is similar as -n 1:

docker container ls -l

The --filter, -f choice permits you to filter the output based mostly on sure standards. For instance, to view solely the containers with standing exited you'd run:

docker container ls -f "standing=exited"
CONTAINER ID    IMAGE        COMMAND                  CREATED        STATUS                    PORTS       NAMES
b28cbaa91f15    couchbase    "/entrypoint.sh couc…"   5 hours in the past    Exited (zero) three hours in the past                db

For an inventory of all supported filters verify the Docker documentation

Conclusion

A Docker container is a standalone runtime occasion of a picture.

To record Docker containers, use the docker container ls command or its alias docker ps.

If in case you have any questions, please depart a remark under.

Comments