In docker I can make docker inspect -f "{{ .NetworkSettings.IPAddress }}" CONTAINER
to run command on a particular container.
What I need is to do something like
docker inspect -f "{{ .NetworkSettings.IPAddress }}" all
or
docker inspect -f "{{ .NetworkSettings.IPAddress }}" *
to run a command on all containers, not mentioning their names explicitly?
It relates to other docker commands as well. Is there such a way without bash scripting?
In order to list the Docker containers, we can use the “docker ps” or “docker container ls” command. This command provides a variety of ways to list and filter all containers on a particular Docker engine. Let's start by listing all the running containers.
If you need to run a command inside a running Docker container, but don't need any interactivity, use the docker exec command without any flags: docker exec container-name tail /var/log/date.
If you mean to create multiple containers at the same time then you will have to make use of docker-compose. This will startup any stopped containers.
You can list multiple container to a docker inspect
.
docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...]
But the only way to list those 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)
The OP f1yegor proposes in the comments:
all=$(sudo docker ps -aq) docker inspect -f "{{ .NetworkSettings.IPAddress }}" $all
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