I want to get a container ID of docker service. Is there any command available for this ?
I tried
docker service ps MyService
but this one only gives the service ID, I am interested in the container id in which the service is running
Container ID – a unique alphanumeric number for each container. Image – The base operating system image the container is based on. Command – The command that launched the container. Created – How long ago the container was created.
Run docker service inspect --pretty <SERVICE-ID> to display the details about a service in an easily readable format.
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.
try combination of docker process filtering and formatting:
docker ps -f name=YOUR_SERVICE_NAME --format "{{.ID}}"
UPDATE
thanks to ahivert for even shorter solution:
# same behavior with
docker ps -f name=YOUR_SERVICE_NAME --quiet
try from
https://github.com/moby/moby/issues/31369
for f in $(docker service ps -q $service);do docker inspect --format '{{.NodeID}} {{.Status.ContainerStatus.ContainerID}}' $f; done
and
docker network inspect --verbose
from https://github.com/moby/moby/pull/31710
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