Reputation: 2359
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
Upvotes: 22
Views: 18286
Reputation: 440
I tried this, it gives me a list of running services:
docker container ls
Upvotes: 1
Reputation: 4853
docker service ps -q -f desired-state=running SERVICE_NAME | xargs docker inspect --format '{{.Status.ContainerStatus.ContainerID}}'
Upvotes: 6
Reputation: 15472
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
Upvotes: 34
Reputation: 32216
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
Upvotes: 13