I want to narrow down the display of docker ps

what's this

--A memo that displays only a part of the result of docker ps --Summary: I can't write it, so read Official Documentation. Especially [Filtering](https://docs.docker.com/engine/reference/commandline/ps/ # filtering).

Preparation

Help display


$ docker ps -h
Flag shorthand -h has been deprecated, please use --help

Usage:  docker ps [OPTIONS]

List containers

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

hello-Create 5 world containers


$ for i in `seq 1 5`; do  docker run hello-world; done
$ docker ps -a -n 5
CONTAINER ID   IMAGE         COMMAND    CREATED              STATUS                          PORTS     NAMES
bcca4b50f397   hello-world   "/hello"   About a minute ago   Exited (0) About a minute ago             cool_hertz
e6d3616b5a67   hello-world   "/hello"   About a minute ago   Exited (0) About a minute ago             clever_chatelet
bd7678b95d36   hello-world   "/hello"   About a minute ago   Exited (0) About a minute ago             zealous_maxwell
e68109080f0b   hello-world   "/hello"   About a minute ago   Exited (0) About a minute ago             agitated_fermi
d59d057989ce   hello-world   "/hello"   About a minute ago   Exited (0) About a minute ago             vigilant_kilby

Show only Running containers

Not displayed because all are exited


$ docker ps
CONTAINER ID   IMAGE            COMMAND                  CREATED          STATUS                      PORTS     NAMES

Squeeze with CONTAINER ID

Show what id is 236858d287f8


$ docker ps -a -f id=bcca4b50f397
CONTAINER ID   IMAGE         COMMAND    CREATED              STATUS                          PORTS     NAMES
bcca4b50f397   hello-world   "/hello"   About a minute ago   Exited (0) About a minute ago             cool_hertz

Squeeze by NAME

NAME is cool_Show what is hertz


$ docker ps -a -f name=cool_hertz
CONTAINER ID   IMAGE         COMMAND    CREATED              STATUS                          PORTS     NAMES
bcca4b50f397   hello-world   "/hello"   About a minute ago   Exited (0) About a minute ago             cool_hertz

Show NAMEs starting with c


$ docker ps -a -f name=^c.*
CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                     PORTS     NAMES
bcca4b50f397   hello-world   "/hello"   2 minutes ago   Exited (0) 2 minutes ago             cool_hertz
e6d3616b5a67   hello-world   "/hello"   2 minutes ago   Exited (0) 2 minutes ago             clever_chatelet

Output only CONTAINER ID

CONTAINER although NAME starts with c_Output ID


$ docker ps -a -f name=^c.* -q
bcca4b50f397
e6d3616b5a67

Output only IMAGE

--See the end of the article about PlaceHolder in format.

Output IMAGE even though NAME starts with c


$ docker ps -a -f name=^c.* --format '{{.Image}}'
hello-world
hello-world

Limit columns

--See the end of the article about PlaceHolder in format.

CONTAINER_Show only ID, NAMES and PORTS columns


$ docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"
CONTAINER ID   NAMES                  PORTS
bcca4b50f397   cool_hertz             
e6d3616b5a67   clever_chatelet        
bd7678b95d36   zealous_maxwell        
e68109080f0b   agitated_fermi         
d59d057989ce   vigilant_kilby  

Containers made before and after 〇〇

NAME=zealous_Before maxwell


$ docker ps -a -f before=zealous_maxwell
CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                     PORTS     NAMES
e68109080f0b   hello-world   "/hello"   4 minutes ago   Exited (0) 4 minutes ago             agitated_fermi
d59d057989ce   hello-world   "/hello"   4 minutes ago   Exited (0) 4 minutes ago             vigilant_kilby

NAME=zealous_After maxwell


$ docker ps -a -f since=zealous_maxwell 
CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                     PORTS     NAMES
bcca4b50f397   hello-world   "/hello"   5 minutes ago   Exited (0) 5 minutes ago             cool_hertz
e6d3616b5a67   hello-world   "/hello"   5 minutes ago   Exited (0) 5 minutes ago             clever_chatelet

From the last to the nth

Last made container


docker ps -l
CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                     PORTS     NAMES
bcca4b50f397   hello-world   "/hello"   5 minutes ago   Exited (0) 5 minutes ago             cool_hertz

From the last to the third


$ docker ps -a -n 3
CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                     PORTS     NAMES
bcca4b50f397   hello-world   "/hello"   5 minutes ago   Exited (0) 5 minutes ago             cool_hertz
e6d3616b5a67   hello-world   "/hello"   5 minutes ago   Exited (0) 5 minutes ago             clever_chatelet
bd7678b95d36   hello-world   "/hello"   5 minutes ago   Exited (0) 5 minutes ago             zealous_maxwell

Squeeze with label

--Reference: Query Label

bash:com.example.is-Everything that has a beta label


$ docker ps --filter "label=com.example.is-beta"

color label value is blue


$ docker ps --filter "label=color=blue"

About PlaceHolder

Placeholder Column name (generally corresponding) Description
.ID CONTAINER ID Container ID
.Image IMAGE Image ID
.Command COMMAND command
.CreatedAt CREATED Date and time of container creation
.RunningFor Calculated from CREATED Time from the start of the container
.Ports PORTS Port to open
.State STATUS Container status(For example; “created”, “running”, “exited”).
.Status STATUS Container status (with details)
.Size SIZE Container size
.Names NAMES Container name
.Labels - All labels on the container
.Label - A specific label on the container. For example'{{.Label "com.docker.swarm.cpu"}}'
.Mounts - Mounted volume
.Networks - Attached network

By the way

Delete all squeezed containers

Delete the last 3 containers


#For the time being, you can erase it by passing all CONTAINER IDs to docker rm with xargs
$ docker ps -a -n 3 -q | xargs docker rm

It is troublesome to squeeze by size

Failure example


#I thought it would be better to have the size column on the far left and then let the sort command handle it.
#The unit is in the way, size/It fails because the virtual size cannot be distinguished because it is in the way
$ docker ps -a -n 3 --format "table {{.Size}}\t{{.ID}}\t{{.Names}}\t{{.Ports}}" | (read -r; printf "%s\n"; sort -k 1)

Recommended Posts

I want to narrow down the display of docker ps
I want to display the name of the poster of the comment
I want to output the day of the week
I want to var_dump the contents of the intent
I want to display the number of orders for today using datetime.
I tried to summarize the state transition of docker
I want to know the answer of the rock-paper-scissors app
I want to be aware of the contents of variables!
I want to return the scroll position of UITableView!
I want to expand the clickable part of the link_to method
I want to change the log output settings of UtilLoggingJdbcLogger
[Rails] I want to display the link destination of link_to in a separate tab
[Ruby] I want to reverse the order of the hash table
I want to temporarily disable the swipe gesture of UIPageViewController
I want to control the display of the upper management navigation bar (Control menu) in Liferay 7 / DXP
I tried to build the environment of PlantUML Server with Docker
The story of Collectors.groupingBy that I want to keep for posterity
I want to limit the input by narrowing the range of numbers
I want to display the images under assets/images in the production environment
I examined the concept of the process to understand how Docker works
I want to control the default error message of Spring Boot
I want to change the value of Attribute in Selenium of Ruby
I want to display background-ground-image on heroku.
I want to display images with REST Controller of Java and Spring!
I want to know the JSP of the open portlet when developing Liferay
[Ruby] I want to extract only the value of the hash and only the key
I want to pass the argument of Annotation and the argument of the calling method to aspect
I want to display an error message when registering in the database
I want you to use Enum # name () for the Key of SharedPreference
After all I wanted to preview the contents of mysql with Docker ...
How to display the result of form input
I want to truncate after the decimal point
[Rails] Implementation procedure of the function to tag posts without gem + the function to narrow down and display posts by tags
I want to get the value in Ruby
Use the where method to narrow down by referring to the value of another model.
[RxSwift] I want to deepen my understanding by following the definition of Observable
I want to get the value of Cell transparently regardless of CellType (Apache POI)
I want to control the start / stop of servers and databases with Alexa
Development memo ~ I want to display only the first image posted multiple times ~
I want to separate the handling of call results according to the API caller (call trigger)
I want to see the contents of Request without saying four or five
I want to recursively get the superclass and interface of a certain class
I want to call a method of another class
[Java] I want to calculate the difference from the date
I want to embed any TraceId in the log
05. I tried to stub the source of Spring Boot
I want to judge the range using the monthly degree
I tried to reduce the capacity of Spring Boot
I want to dark mode with the SWT app
I want to call the main method using reflection
[WIP] I tried the configuration of Docker + Streama + NFS
[Rough commentary] I want to marry the pluck method
I want to simplify the log output on Android
I want to add a delete function to the comment function
[Ruby] I want to make a program that displays today's day of the week!
Rails The concept of view componentization of Rails that I want to convey to those who want to quit
[Must-see for beginners] I changed the display of the posting time to Japanese time [l method]
I want to see only the latest because the Docker log has become too large
[Active Admin] I want to specify the scope of the collection to be displayed in select_box
I want to reduce the number of unnecessary queries. From considering counter_cache to introducing counter_culture.
I want to fetch another association of the parent model from the intermediate table with has_many