Marian Zagoruiko
Marian Zagoruiko

Reputation: 1596

How to get docker system ID inside container?

As far as I understand each docker installation has some kind of a unique ID. I can see it by executing docker system info:

$ docker system info

 // ... a lot of output
 ID: UJ6H:T6KC:YRIL:SIDL:5DUW:M66Y:L65K:FI2F:MUE4:75WX:BS3N:ASVK
 // ... a lot of output

The question is if it's possible to get this ID from the container (by executing a code inside container) w/o mapping any volumes, etc?

Edit: Just to clarify the use case (based on the comments): we're sending telemetry data from docker containers to our backend. We need to identify which containers are sharing the same host. This ID would help us to achieve this goal (it's kind of machine id). If there's any other way to identify the host - it can solve the issue as well.

Upvotes: 2

Views: 3352

Answers (2)

Neo Anderson
Neo Anderson

Reputation: 6350

No - unless you explicitly inject that information in the container(volumes, COPY, environment variable, ARG passed at build time and persisted in a file etc), or you fetch it via a GET request for example, that information is not available inside the docker containers.

You may open a console inside a container and search for all files that contain that ID grep -rnw '/' -e 'the-ID' but nothing will match the search.

On the other hand, any breakout from the container to the host would be a real security concern.


Edit to answer the update on you question:

The docker host has visibility on the containers that are running. A much better approach would be to send the information you need from the host level rather than container level.
You could still send data directly from the containers and use the container ID, which is known inside the container and correlate these telemetry information to the data sent from the docker host.

Yet another option, which is even better in my opinion, is to send that telemetry data to the stdout of the container. This info can easily be collected and send to the telemetry backend on the docker host, from the logging driver.

Upvotes: 2

Itamar Turner-Trauring
Itamar Turner-Trauring

Reputation: 3890

Often the hostname of the container is the container ID--not the ID you're talking about, but the ID you would use for e.g. docker container exec, so it's a fine identifier.

Upvotes: 0

Related Questions