I haven't found any way to order my results when using docker ps
In my case I want to order by .Ports
docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"
How do I order the result?
The 'docker ps' is a Docker command to list the running containers by default; however, we can use different flags to get the list of other containers that are in stopped or exited status. We can also manipulate the output as per our requirement using flags.
By default, docker inspect will render results in a JSON array.
The left-hand side of the port number mapping is the Docker host port to map to and the right-hand side is the Docker container port number. When you open the browser and navigate to the Docker host on port 8080, you will see Jenkins up and running.
You can check with this command systemctl status docker it will show the status of the docker. If you want to start you can use systemctl start docker instead of systemctl you can try also with service , service docker status and service docker start respectively.
If it's enough to simply sort by output column, you can use the following:
docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}" | (read -r; printf "%s\n" "$REPLY"; sort -k 3 )
I also added a code for skipping the table headers and sorting only ps output data.
List containers
docker ps
Synopsis
docker ps [--format="TEMPLATE"]
--format="TEMPLATE"
Pretty-print containers using a Go template.
Valid placeholders:
.ID - Container ID
.Image - Image ID
.Command - Quoted command
.CreatedAt - Time when the container was created.
.RunningFor - Elapsed time since the container was started.
.Ports - Exposed ports.
.Status - Container status.
.Size - Container disk size.
.Names - Container names.
.Labels - All labels assigned to the container.
.Label - Value of a specific label for this container. For example {{.Label "com.docker.swarm.cpu"}}
.Mounts - Names of the volumes mounted in this container.
Display containers with their commands
docker ps --format "{{.ID}}: {{.Command}}"
Display containers with their labels in a table
docker ps --format "table {{.ID}}\t{{.Labels}}"
Display containers with their node label in a table
docker ps --format 'table {{.ID}}\t{{(.Label "com.docker.swarm.node")}}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With