Docker Community Forums

Share and learn in the Docker community.

What is my DTR Replica ID?


(Anthony Alcamo) #1

Within the UCP Web UI, I can view the Replica of my DTR Node via Resources | Stacks & Applications | Docker Trusted Registry x.x.x - [Replica ReplicaID]. Clicking on the replica shows the Node’s hostname to which the DTR services have been deployed and are running. Is it possible to determine a DTR’s Replica ID from the CLI? I have viewed all of the API docs for docker/dtr (e.g. run -it docker/dtr --help). Thank you.


(Joao Fernandes) #2

I don’t think the docker/dtr image has any command that allows you to do this.
If you ssh into a node that you know is running DTR, you can do something like

docker ps --format "{{.Names}}" | grep dtr

This lists all DTR containers, their name will be appended with the DTR replica ID.


#3

If I’m doing this from a Linux/Unix shell script, I do the following:

# `from __future__ import ...` ensures both python2 & python3 compatibility.
PY_UCP_AUTH_TOKEN="from __future__ import print_function; import sys, json; print(json.load(sys.stdin)['auth_token'])"
AUTH_TOKEN="$(curl -k -s -H "Content-Type: application/json" -X POST -d \
              '{"username":"'${UCP_ADMIN}'", "password":"'${UCP_PASSWORD}'"}' \
              "${UCP_URL}/auth/login" | python -c "${PY_UCP_AUTH_TOKEN}")"
DTR_REPLICA_ID="$(curl -s -X GET "${UCP_URL}/containers/json" \
               -H "accept: application/json" \
               -H "Authorization: Bearer ${AUTH_TOKEN}" |
               sed -rn 's|^.*Replica ([A-Za-z0-9]*).*$|\1|p' |
               head -n 1)"

#4

Here’s a pro tip I got from one of our engineers: REPLICA_ID=$(docker inspect -f '{{.Name}}' $(docker ps -q -f name=dtr-rethink) | cut -f 3 -d '-')

Hope it helps!