'docker ps' output formatting: list only names of running containers
BashDockerBash Problem Overview
docker ps --format "table {{.Names}}"
output NAMES
in first row:
root@docker-2gb-blr1-01:~# docker ps --format "table {{.Names}}"
NAMES
enr
osticket
osticket_db
...
docker inspect --format '{{.Name}}' $(docker ps -q)
prints /
in the beginning of container name:
root@docker-2gb-blr1-01:~# docker inspect --format '{{.Name}}' $(docker ps -q)"
/enr
/osticket
/osticket_db
I want to list only names of running containers, without header or slash in beginning. Please share options how to do this.
Bash Solutions
Solution 1 - Bash
Try removing the table
part from your --format
argument, such as:
docker ps --format '{{.Names}}'
It should give you a simple list of container names with no table heading
Solution 2 - Bash
Here is how we query the other columns with docker ps
.
Names:
docker ps --format '{{.Names}}'
ID:
docker ps --format '{{.ID}}'
Image:
docker ps --format '{{.Image}}'
Command:
docker ps --format '{{.Command}}'
Created:
docker ps --format '{{.RunningFor}}'
Status:
docker ps --format '{{.Status}}'
Ports:
docker ps --format '{{.Ports}}'
More information can be found here.
Solution 3 - Bash
Just a combination command, it is prettified with table
.
$ docker ps --format "table {{.Image}}\t{{.Ports}}\t{{.Names}}"
IMAGE PORTS NAMES
nginx 0.0.0.0:80->80/tcp nginx
In addition you can add it to .docker/config.json
file that will allow you to customize the output of your docker ps
command.
add to ~/.docker/config.json
:
{
"psFormat": "table {{.ID}}\\t{{.Image}}\\t{{.Status}}\\t{{.Names}}"
}