You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
In our weave network we launch several distributed apps in containers on different hosts.
We name containers for myapp as myapp-1, myapp-2, myapp-N to be able to address them separately (for example from load balancers).
Also for some application we give them custom host names as myapp-master (for myapp-1) and myapp-slave (for myapp-2 .. myapp-N) to make use of DNS balancing.
Current version of weave automatically manages only {{.Config.Hostname}}.{{.Config.Domainname}} value. See watcher.go code.
We've made a quick poc to automatically add not only hostname, but also container name if it differs:
diff --git a/plugin/net/watcher.go b/plugin/net/watcher.go
index 9a79561..c17f48b 100644
--- a/plugin/net/watcher.go
+++ b/plugin/net/watcher.go
@@ -46,6 +46,13 @@ func (w *watcher) ContainerStarted(id string) {
if err := w.weave.RegisterWithDNS(id, fqdn, net.IPAddress); err != nil {
w.driver.warn("ContainerStarted", "unable to register %s with weaveDNS: %s", id, err)
}
+ alias := fmt.Sprintf("%s.weave.local.", info.Name[1:]) // Remove prefix slash from name
+ // w.driver.warn("ContainerStarted", "Container alias: %s", alias)
+ if ( alias != fqdn ) {
+ if err := w.weave.RegisterWithDNS(id, alias, net.IPAddress); err != nil {
+ w.driver.warn("ContainerStarted", "unable to register %s with weaveDNS: %s", id, err)
+ }
+ }
}
rootDir := "/"
if w.driver.isPluginV2 {
This works fine and do the job nicely.
Is it possible to add such a functionality into main branch? I can submit PR if there is a chance for it to be accepted.
If possible, please advice how can I refer custom domain suffix (supplied with --dns-domain option) inside ContainerStarted method of watcher? For sake of simplicity I've hardcoded it into my POC snippet.
This functionality can also rely on some container labels, such as weave.works.dns-alias or something.
The text was updated successfully, but these errors were encountered:
I was pondering whether this might be harmful to someone who uses container names for some other purpose and doesn't expect them to resolve via DNS but, as discussed on Slack, Docker itself will actually resolve the container name if you query from the same host (not cross-host unless you use the plugin in "global scope"). So guess it's not dangerous for Weave to add the name.
I'm less clear about the domain - why wouldn't you want to use config.Domainname ?
Could query the Weave Net daemon for its domain via api.DNSDomain()
Lastly, note there is a --net-alias option that could be used (and implemented here) instead of labels. See #1975 (and also #1914)
@bboreham thanks for --net-alias tip, implemented that as well.
As for domain name, config.Domainname is rarely used and is usually empty – it can't be populated via docker CLI in late docker versions and via docker_container ansible module, see moby/moby#27067 issue and related PR moby/moby#20200 (which stopped splitting fqdn). So I think it is safe to add configured weave domain as suffix to container name, because we already know that this container is in "our" network.
In our weave network we launch several distributed apps in containers on different hosts.
We name containers for
myapp
asmyapp-1
,myapp-2
,myapp-N
to be able to address them separately (for example from load balancers).Also for some application we give them custom host names as
myapp-master
(formyapp-1
) andmyapp-slave
(formyapp-2
..myapp-N
) to make use of DNS balancing.Current version of weave automatically manages only
{{.Config.Hostname}}.{{.Config.Domainname}}
value. See watcher.go code.We've made a quick poc to automatically add not only hostname, but also container name if it differs:
This works fine and do the job nicely.
Is it possible to add such a functionality into main branch? I can submit PR if there is a chance for it to be accepted.
If possible, please advice how can I refer custom domain suffix (supplied with
--dns-domain
option) insideContainerStarted
method of watcher? For sake of simplicity I've hardcoded it into my POC snippet.This functionality can also rely on some container labels, such as
weave.works.dns-alias
or something.The text was updated successfully, but these errors were encountered: