Docker: Is there a `docker ps` command that lists only privileged containers?

Viewed 1012

I wish to get the list of only privileged docker containers. docker ps lists all running containers by default. I combed the documentation but couldn't find anything.

Is it possible using the API or is there some other way doing it?

1 Answers

There may be a better way to do this but using shell you could do something like:

 docker inspect --format='{{.ID}} {{.HostConfig.Privileged}}' $(docker ps | awk '{if(NR>1) print $1 }') | grep true

docker inspect will inspect an individual container. The property that we are checking is .HostConfig.Privileged

--format will return the id and true or false if the container is prvileged. $(docker ps | awk '{if(NR>1)

we use command substitution at the end to return the ids of containers from docker ps

Edit to make command more efficient

Improvement as per comment removes the pipe to awk and makes the command more efficient. To display only the privileged containers containers the result is piped to grep looking for true.

docker inspect --format='{{.ID}} {{.HostConfig.Privileged}}' $(docker ps --format='{{.ID}}') | grep true 

If we remove the last pipe we will list all running containers and a true or false flag to indicate privileged status

docker inspect --format='{{.ID}} {{.HostConfig.Privileged}}' $(docker ps --format='{{.ID}}')
Related