Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'docker ps' output formatting: list only names of running containers

Tags:

bash

docker

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.

like image 356
Paul Serikov Avatar asked Jun 03 '18 14:06

Paul Serikov


People also ask

Which command is used to list out only running docker containers?

In order to list the Docker containers, we can use the “docker ps” or “docker container ls” command.

What is the command in docker to list all running containers Mark Mark?

docker ps --no-trunc will display the full command along with the other details of the running containers.

What is the output of docker ps command?

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.


2 Answers

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

like image 165
whites11 Avatar answered Oct 08 '22 22:10

whites11


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.

like image 33
nPcomp Avatar answered Oct 08 '22 21:10

nPcomp