traefik / whoami

Tiny Go server that prints os information and HTTP request to output

Home Page:https://traefik.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Suggestion] Add container ID

McDefault opened this issue · comments

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?

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

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

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

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.

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

whoami/app.go

Lines 211 to 212 in 2d6ebed

hostname, _ := os.Hostname()
_, _ = fmt.Fprintln(w, "Hostname:", hostname)

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