Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get container id of a docker service

Tags:

docker

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

like image 580
Akki Avatar asked May 09 '17 11:05

Akki


People also ask

What is the container ID in docker?

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.

Which command shows the service container ID on the local docker host?

Run docker service inspect --pretty <SERVICE-ID> to display the details about a service in an easily readable format.

How do I list a running docker container?

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.


2 Answers

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
like image 163
Andriy Avatar answered Sep 22 '22 16:09

Andriy


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

like image 43
user2915097 Avatar answered Sep 22 '22 16:09

user2915097