Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide container name (and/or its number) in environment variables #2432

Closed
valyagolev opened this issue Nov 20, 2015 · 2 comments
Closed

Comments

@valyagolev
Copy link

It would be very useful if there was a way to find out the container name (like, projectname_webserver_1) from inside of it, to use it as some kind of an id (like for kafka, or in the logs).

The only way to get it which I could find is by parsing it out from some *_NAME environment variable, which requires the container to have links, and feels bad.

@dnephin
Copy link

dnephin commented Nov 20, 2015

You can use the hostname as a unique id, which is the unique container id, by using $(hostname).

This issue is a duplicate of #1503

@dnephin dnephin closed this as completed Nov 20, 2015
@sparrowt
Copy link

sparrowt commented Dec 12, 2024

It's a shame this and duplicate have been closed without an official way to get the container name. The best seems to be this workaround which requires having dig installed in the container.

I realise that the hostname contains the container id and I do log this, but it would be much more helpful to filter by name as this immediately conveys meaning when looking at the logs and also can be filtered on long-term (across multiple different containers over time).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants