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 ?
Asked
Active
Viewed 2,290 times
1 Answers
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.