简体   繁体   中英

Printing docker container id in Spring boot app

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM