-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Inject chosen container name in container #1503
Comments
I think with the new networking support coming in the next release, you'll be able to use hostname for this instead of container name. |
#2334 (comment) has another use case for this. I think this may also address the issue raised in #1131 Using a predefined environment variable (as implemented in #1504) seems like a reasonable way to implement this. The only other option would be to set the hostname, but we saw that was disruptive to other use cases. One potential problem is that containers can be renamed, but the environment variable would not get updated on a rename (there is no way to update the environment). So when it gets renamed, the value would be incorrect. Another option might be to use I don't know of any other way we can set this in the container. |
What about /etc/container_name (we already have debian_version, system-release, etc.). Anybody can grep/cat the value and it can be changed on the fly. |
So, the final decision is just to use uid (hostname) and ignore the fact that there are use cases where it's simply not enough? |
There hasn't been any decision made about this yet. The case you describe in #2334 seems to be pretty rare, and maybe is more of an issue with Registrator being too limited about how it registers containers. Other container-dns solutions support ways to override the name.
I don't think there are any facilities for adding files to the container at runtime, and we won't want to be adding an extra volume to every container. The approach of using an environment variable breaks when containers are renamed, so we don't yet have a reliable alternative to using the unique hostname. |
:/ I agree with you on the statements. However, I thought that Registrator+Consul isn't so rare :) I solved it already with custom microservice managing alternative hosts as I want it, but that's not perfect solution and I will start looking for alternatives soon.
Could you help me and name some? |
https://github.com/crosbymichael/skydock#plugin-support These are the ones I know about |
any update on this? quite frustrating that each container just get a random id as hostname, and not |
We are still trying to understand why a container needs to know its name instead of just a unique id. If you could provide more information about your use case that would be valuable. There is no clear solution to this yet because: the problem is not yet well understood, and the proposed solutions will break with container renaming. The only update is that with the new aliasing being proposed for user defined networks it should be possible for a container to query dns for alternative CNAME entries, which gives you an option for determining the service name. |
for my case, i use the hostname to sniff out the service group the container is part of, and the scale of it (from e.g. tutum.co and rancher) - based on that, i can deduce if the container should be doing different things, e.g. try to scan and figure out how many "siblings" it got as well.. also, in consul, the hostname is the identifier for the container(s), so having their id as hostname makes it impossible to get an easy-to-understand overview of what nodes are currently running or not |
@dnephin i would like to setup Jenkins with one master node, and two slaves nodes. the Jenkins slave nodes share the same image, and thus using admittedly, i can create |
+1 |
I too have a use case. I am writing a test case in which I want my container that runs a Java JMS client. I want to use the scale feature and have each JMS client use its scale index as part of its selector for both its producers and its consumers. Not having this is painful as I have to copy the section in my docker-compose.yml for the client, making as many copies as I want instances to run, and explicitly set the param I want in the environment of each copied section. |
My use case is simply i want my kafka consumer to be set to different partition number on each container. Wanted to parse the container name from env to set it. |
Use case: I want my |
I want the first copy of a scaled service to use a known id for something and all of the other copies to gen new ids for themselves then wait for the first container to touch a file. |
I aggregate app errors in Sentry. In Senry i want to see container name instead of just id. So the app must khow container name |
I want to do simple logging to file inside application and being able to scale the containers, redirecting logs from each instance to different directories. |
Another use case is being able to monitor in flower (celery tasks, potentially also airflow celery executors) which container name (in our case it is a container per queue environment) is executing each task and not only in which host is the container running. |
We're using a microservice architecture where services provide RPCs on an RPC-engine. It would be nice to use the stack declaration (compose file) to give the services on that sub-system the same name as declared in the compose file. It is possible by setting some environmental to the same name, but it would be nice to just be able to use the service name specified in the compose file. |
use case: we want to know container name when using For example: container name is abc.2.yqta2ftatvgggik5d6090eglk, so jvmRoute will be 2. Using hostname as jvmRoute value works, but that will be a little harder to debug. For example, if jvmRoute is 2, the sessionid generated by tomcat will be xxxxxx.2. So I can immediately know the problem is related to no.2 task. If jvmRoute is hostname like f7edcdee2ac4, the sessionid generated by tomcat will be xxxxx.f7edcdee2ac4, then i have to do some searching to know which task is related to. |
I need a unique username for registration with a service that is only necessary at runtime, and it would ideally be meaningful for debugging. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it had not recent activity during the stale period. |
shame it was closed. We have a very similar usecase to other people. |
I bring up my services in docker compose and want the container name to get dynamic configuration from a remote configuration service. A hack i'm using inside my docker container, doing a reverse DNS lookup. I'm removing the scale number cause i don't want it for my use case. #!/bin/bash
get_service_name() {
ip="$(cat /etc/hosts | grep -E '172\.|192\.|10\.' | awk '{print $1}')"
dig +noall +answer -x "$ip" | awk '{print $5}' | cut -f2 -d _
}
get_service_name |
Thanks a lot @tommymcguiver, I have updated |
@tommymcguiver I think you can shorten that to: dig -x "$(hostname -i)" +short | cut -d _ -f 2 (The |
Because it can be desirable for monitoring, having the container name accessible in the container could be useful.
Use case include:
Currently, there is not way to get the container name apart from being outside the docker, or being able to talk to the docker daemon. This is clearly not something we want from out inner applications. I suggest passing a simple environment variable could do the trick in most case.
The text was updated successfully, but these errors were encountered: