4

I have a spring boot app in docker. This app is scaled up and can run on multiple containers. I want the app to print the container id . How can I do this ?

RDR
  • 473
  • 4
  • 15

1 Answers1

1

A docker ps would display it.
Or a docker inspect --format="{{.Id}}" <container_name>

But if your goal is to access that id from the container itself, see "Docker, how to get container information from within the container?"

For instance:

awk -F"-|\." '/1:/ {print $3}' /proc/self/cgroup

If you can put that information in a file at the start of your Spring Boot app, then that same application can access that file, read it and display said information.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250