Don Collett
Don Collett

Reputation: 29

How to get the Docker Container Id from inside a running docker image via Java API?

Not finding anything on the University of Google so checking here. I have an enterprise application running on an application server inside a docker image. During the running time, the enterprise application needs to use a Java API call to obtain the Docker Container Id that it's running in. How is this done?

Upvotes: 0

Views: 3434

Answers (1)

Salem
Salem

Reputation: 12986

In general, when docker runs a container it should set the hostname with the id of the container, so just reading the environment variable HOSTNAME (or the file /etc/hostname) should do it.

If this does not work, provide more information about your setup.

Upvotes: 5

Related Questions