YouTube Icon

Code Playground.

How to List Containers in Docker

CFG

How to List Containers in Docker

Docker is a containerization stage that permits you to rapidly fabricate, test, and send applications as compact, independent compartments that can run for all intents and purposes anyplace. It is the accepted norm for holder organization, and it is a basic device for DevOps engineers and their consistent mix and conveyance pipeline. 

In this article, we'll disclose how to list Docker compartments. 

List Docker Containers

The Docker order for posting holders takes the accompanying structure: 

docker container ls [options]

More seasoned Docker forms before 1.13 are utilizing an alternate order to list the compartments: 

docker ps [options]

The order above is actually upheld in fresher Docker adaptations where the ps order is a moniker to compartment ls. 

To list the running compartments, execute the docker holder ls order with no choice: 

docker container ls

The yield will look something like this: 

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

Each line of the yield incorporates the accompanying segments: 

  • Holder ID – An interesting alphanumeric string that distinguishes every compartment. 
  • Picture – The Docker picture that is utilized to make the holder. 
  • Order – The order that is executed when beginning the holder. 
  • Made – The creation season of the holder. 
  • Status – The status of the holder. 
  • Ports – The holder's distributed ports. 
  • Name – The name of the holder. 

On the off chance that there are no running compartments, just the header line is shown. 

The - a, - all alternative advises docker compartment ls to print a rundown, all things considered: 

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

Naturally, segments with a length surpassing a predefined limit are shortened. Utilize the - no-trunc alternative to impair truncation: 

docker container ls --no-trunc

To just show the compartments' IDs pass the - q, - calm choice: 

docker container ls -q
c8bded53da86
571c3a115fcf
05ef6d8680ba

The - design permits you to arrange the yield utilizing a Go format. For instance, to print just the compartments' names and status, including the header, you would run: 

docker container ls --format 'table {{.Names}}\t{{.Status}}'
NAMES    STATUS
pg       Up 2 hours
cache    Up 4 hours
web      Up 2 hours

Utilize the - s, - size alternative to see the size of the holders: 

docker container ls -s

Each line will incorporate a section named SIZE that shows the holder size: 

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

The - keep going, - n alternative advises the order to show n last made holders, including all states. For instance, to see the most recent two made holders, you would run: 

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

There is additionally a choice to list just the most recent made holder - most recent , - l which is same as - n 1: 

docker container ls -l

The - channel, - f choice permits you to channel the yield dependent on specific rules. 

For instance, to see just the holders with status left, you would run: 

docker container ls -f "status=exited"
CONTAINER ID    IMAGE        COMMAND                  CREATED        STATUS                    PORTS       NAMES
b28cbaa91f15    couchbase    "/entrypoint.sh couc…"   5 hours ago    Exited (0) 3 hours ago                db

For a rundown of every single upheld channel, check the Docker documentation 

Conclusion

A Docker holder is an independent runtime case of a picture. To list Docker holders, utilize the docker compartment ls order or its nom de plume docker ps. 

On the off chance that you have any inquiries, it would be ideal if you leave a remark beneath.




CFG