-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Switch to using hyphens as a separator in hostnames #229
Comments
also see: moby/moby#5418 |
This is causing pain for me as well, in pretty much the exact same scenario (the hostname being parsed by Java's standard library URI parser). Is this a fig issue, or should it be fixed in docker? |
Frustratingly, underscores are invalid in hostnames, and dashes are invalid in shell variable names. So if you can't name a Docker link without either breaking one of those or smushing everything together (e.g. However, looks like moby/moby#6270 might fix this by sanitising environment variable names, in which case Fig can switch to dashes and everything will hopefully work: web:
links:
- hadoop $ fig run web cat /etc/hosts
...
172.17.0.42 hadoop-1
...
$ fig run web env
...
HADOOP_1_PORT=tcp://172.17.0.42:5432
HADOOP_1_PORT_5432_TCP=tcp://172.17.0.42:5432
HADOOP_1_PORT_5432_TCP_ADDR=172.17.0.42
... |
#349 is also relevant. |
Technically speaking, I don't believe that hyphens in shell variable names are strictly forbidden. You just can't access them in the normal way: $ env foo-bar=baz bash
$ printenv foo-bar
baz |
👍 switching to hyphens |
What about writing both hyphenated and underscored to the hosts file for now? |
@zeeraw that would be out of fig's scope - a job for docker itself. |
We can do this now that moby/moby#5418 has been fixed, right? |
Ugh java's URI is so annoying. The single-value constructor does not throw an exception for underscores in the hostname.
|
Will this also be used for the container names? If so, I think moby/moby#8961 should also be taken into account. |
We could add aliases for dashes when we implement #2312, keep both underscores and dashes for a release or two, then drop support for underscores in hostnames. |
Same here, cannot run spark cluster with docker-compose. Showstopper |
@susu Why is this a showstopper? The problem of underscores in hostnames is easily worked around, either with link aliases or by changing service names. |
Nope, because spark somehow extracts the underscored hostname of docker
|
However it's doing that, that's the wrong thing to do. Is this an image you're using from the Hub, or did you build it yourself? Switching back to version 1 is not a future-proof solution. |
@susu The workaround I used for this was to create a network so I could control the name:
Use that as an external network in my (version 2) docker-compose.yml file:
Connect each service to that network:
And finally override the container name and hostname in the spark worker service:
|
P.S. I determined that the spark worker is using reverse DNS lookup on its IP address to get the DNS name to register with the master. |
Thanks @gordontyler ! I didn't know I can override container and hostname! Already migrated to version 2 :) @aanand I know version 1 is not future-proof, however at the moment I'm only creating a PoC with spark, so clean, production-grade solution is not a must-have :) But anyway, using @gordontyler 's solution, I can go forward with version 2! Thank you guys! |
FYI, that issue has also been raised in Docker Forum as Underscore in domain names. In particular, I explain there where & why Spark (from version 1.6.x) doesn't allow underscores in hostnames.
|
I am having this problem as well, related to Hazelcast. I can work around it using fixed container names without underscores but it precludes the use of the docker-compose scaling mechanism since the system assigned name is mystack_myservice_n. |
389 directory server's admin console, 389-console, is not able to handle the underscores in container DNS names, but adding a network alias hostname with no underscores resolved that. I wasn't even able to complete the directory server configuration until adding the hostname aliases with no underscores. I had to also use "StrictHostCheck = false" in the initial-setup.inf file and "/usr/sbin/setup-ds-admin.pl --silent --file=initial-setup.inf General.StrictHostCheck=false" when installing the directory server binaries, admin server binaries and the initial directory configuration. This was because Docker DNS is a can of worms regarding reverse DNS entries. |
Is this being done any time soon? This makes docker-compose unusable with many languages, which is really unfortunate. |
How is this still an issue after 6 years? This is a basic DNS violation.
This makes compose absolutely useless for more "strict" or rather correct tools. |
Reading through this thread, there don't appear to be any real arguments against the proposed change. (Perhaps I missed them?) Are there any philosophical or practical reasons that a PR to address this would not be merged, or is this simply a matter of nobody putting in the work yet? |
+1 |
This is a problem with Tomcat (and, by extension, with many Spring Boot applications) too: https://stackoverflow.com/q/53504857/1374678 |
Just got bit by this myself. Connecting two containers from different services should have been a breeze, instead it has been a day-long nightmare. Please fix this. It has been open for almost seven years. |
I discovered that we can put dots in service aliases! That means that I can define names how I want them: in FQDN format and no underscores. I have scripting that standardizes our docker-compose.yml files and automatically defines services under the RFC6762 |
Rename your containers to change the underscores to hyphens. IMHO - the documentation should indicate that container names that include characters that are not valid for hostnames might break, dependent on the underlying server URL parser (e.g. Spring, tomcat) |
eventually closing this issue, by Compose V2 hostname will be set using hyphens, unless |
Whoa this is a big change to spring on users after it wasn't enabled in the last RC (it's the default even for existing projects). Is there a way to make this setting global e.g. via a config file, rather than updating all my scripts? |
Use this env variable instead: |
→ docker compose --help
Options:
--compatibility Run compose in backward compatibility mode |
@ndeloof something is messed with the command line. This command works:
This doesn't:
This doesn't either:
Version on MacOS:
Edit: Command is ment to be like this I guess:
It takes some getting used to :-S |
"compatibility" applies to the top-level "compose" verb:
|
MinIO, which is a S3-compatible storage solution, doesn't support underscores in given hostnames anymore. Which means all my stacks that are deployed in my docker swarm with As far as I know compose verison 3 uses underscores like this: |
@Issykul This is how I solved the problem in Docker compose file:
|
Docker's default DNS service naming is a little silly because it does not take advantage of standard DNS hierarchy conventions, which could still be useful. I like to ignore Docker's automatic service names and define my own instead, just as @aki-k suggested. The only difference is that I like to make mine fully qualified. Doing it this way allows me to use filter the top-level domain and avoid hammering my upstream nameservers if a service isn't up yet. I could filter all unqualified names, but I don't like that. I like to name things [service].[stack].[network].private, for example:
|
The hostname format used by fig creates names that are not strictly valid.
Current pseudo-code:
This generates names like
cluster_hadoop_1
. Underscores are not valid (though in practice most components are tolerant of this).Valid names should match
[a-zA-Z0-9\-]+
.I came across this error when trying to test out some hadoop/hdfs containers and hadoop bailed with an exception saying that
hdfs://flume_hadoop_1/
was not valid URI (even though it was in/etc/hosts
andping flume_hadoop_1
worked just fine).See: http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
Changing this to dashes is easy, but it would break existing configurations that depend on hard coded container names.
The text was updated successfully, but these errors were encountered: