Skip to content

Commit b33f85a

Browse files
committed
Register containers with both _ and -
As `_` is not allowed in FQDN some applications might not accept to use docker compose generated container names. This commit will register an alternative version using `-` instead of `_`.
1 parent 12371ea commit b33f85a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

dockerDDNS.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def register_container(container_id):
4242
nsupdate.stdin.write(bytes(zone_update_template.format(container_hostname, args.domain, container_ip), "UTF-8"))
4343
if container_name != container_hostname:
4444
nsupdate.stdin.write(bytes(zone_update_add_alias_template.format(container_name, args.domain, container_hostname), "UTF-8"))
45+
if re.search("_", container_name):
46+
alternate_name = re.sub('_','-',container_name)
47+
logging.info("Adding alternate name %s to %s", alternate_name, container_name)
48+
nsupdate.stdin.write(bytes(zone_update_add_alias_template.format(alternate_name, args.domain, container_hostname), "UTF-8"))
4549
nsupdate.stdin.write(bytes("send\n", "UTF-8"))
4650
nsupdate.stdin.close()
4751

@@ -114,7 +118,7 @@ def remove_container(container_id):
114118
register_container(container["Id"])
115119

116120

117-
# Too bad docker-py does not currently support docker events
121+
# TODO use docker-py streaming API
118122
events_pipe = Popen(['docker', 'events'], stdout=PIPE)
119123

120124
while True:

0 commit comments

Comments
 (0)