traefik / whoami

Tiny Go server that prints os information and HTTP request to output
https://traefik.io
Apache License 2.0
1.04k stars 223 forks source link

[Suggestion] Add container ID #60

Closed McDefault closed 2 years ago

McDefault commented 2 years ago

I'm using this repo to check my Docker container id

They are displaying it with python like so:

import socket
container_hostname = socket.gethostname()
@app.route('/')
def index():
    url = random.choice(images)
    return render_template('index.html', url=url, hostname=container_hostname)

source

Now my question is: is it possible to add container ID info to this list in whoami?

ldez commented 2 years ago

Hello,

this is not really the container ID but the system hostname.

The Python function socket.gethostname() returns the host name of the current system under which the Python interpreter is executed

https://pythontic.com/modules/socket/gethostname

McDefault commented 2 years ago

Correct. Im aware of that. However. It does corrolate with the container ID

ldez commented 2 years ago

The container ID is a hash. You are talking about the container "name"

ldez commented 2 years ago

From the point of view of whoami, it doesn't know if there is a container or not.

I think your request is about adding the hostname information to some endpoints of the whoami.

ldez commented 2 years ago

The hostname is already a part of the information returned by the whoami.

https://github.com/traefik/whoami/blob/2d6ebedb0f2217d81d26c8672d81d3d26a587e7a/app.go#L211-L212

McDefault commented 2 years ago

The container ID is a hash. You are talking about the container "name"

I don't mean the name, but i understand the confusion. Actually is it indeed already there. like you said.

I just realised I overrode it with the hostname property in my compose-file so it dind't show the correct container_ID.

Anyways good to see it's already there! Thank for the replies trying to help