How to run Docker query command on all containers?

In docker, I can do docker inspect -f "{{ .NetworkSettings.IPAddress }}" CONTAINER

to run a command in a specific container.

Do I need to do something like docker inspect -f "{{ .NetworkSettings.IPAddress }}" all

or docker inspect -f "{{ .NetworkSettings.IPAddress }}" *

execute a command in all containers without explicitly specifying their names?

This applies to other docker commands as well. Is there such a way without bash scripts?

+3


source to share


1 answer


You can list multiple containers in docker inspect

.

docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...]

      

But the only way to list this container is through bash $(sudo docker ps -aq)

.

For example:



docker inspect --format='{{.Name}}' $(sudo docker ps -aq)
docker inspect -f "{{ .NetworkSettings.IPAddress }}" $(sudo docker ps -aq)

      

OP f1yegor suggests in the comments :

all=$(sudo docker ps -aq) docker inspect -f "{{ .NetworkSettings.IPAddress }}" $all 

      

+4


source







All Articles