简体   繁体   中英

Is this possible to get all running containers id's in docker swarm services?

I am newbie in docker swarm mode, If I want more details about my swarm service , from command line I can run docker service ps "service name ", or from docker rest "/v2/services/my-ngx"

[msreddy@swarmnode1 ~]$ docker service ps my-ngx ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS voj7fllhnmqb my-ngx.1 nginx:latest swarmnode1 Running Running 26 minutes ago

but it didn't give me container id. I want track containers form my swarm service is this possible ?

docker service ps my-ngx返回的ID是<task_id>要获取容器ID,可以使用docker inspect -f "{{.Status.ContainerStatus.ContainerID}}" <task_id>

The Solution of prranay work perfectly. To put it together with the question asked (bash):

for f in $(docker service ps -q my-ngx -f desired-state=running);do docker inspect --format '{{.Status.ContainerStatus.ContainerID}}' $f; done

This lists all containers of the mentioned service my-ngx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM