Skip to content
Snippets Groups Projects
Commit daf285f4 authored by Zsombor Welker's avatar Zsombor Welker
Browse files

Generate names for docker-compose

parent 1ffe353f
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ an exact match is required. If a generated domain address doesn't match the list ...@@ -28,7 +28,7 @@ an exact match is required. If a generated domain address doesn't match the list
d6d51528ac46 alpine "/bin/sh" 8 seconds ago Up 6 seconds relaxed_cartwright d6d51528ac46 alpine "/bin/sh" 8 seconds ago Up 6 seconds relaxed_cartwright
``` ```
1. `<container_hostname>.<default_domain>`, `<container_hostname>.<container_domain>.<default_domain>`, `<container_hostname>.<container_domain>` 2. `<container_hostname>.<default_domain>`, `<container_hostname>.<container_domain>.<default_domain>`, `<container_hostname>.<container_domain>`
If an explicit `--hostname` is provided then that may also be used: If an explicit `--hostname` is provided then that may also be used:
```sh ```sh
...@@ -49,7 +49,7 @@ an exact match is required. If a generated domain address doesn't match the list ...@@ -49,7 +49,7 @@ an exact match is required. If a generated domain address doesn't match the list
docker run --rm -it --hostname test --domainname local alpine # test.local docker run --rm -it --hostname test --domainname local alpine # test.local
``` ```
1. `<container_name>.<container_network>.<default_domain>`, `<container_name>.<container_network>` 3. `<container_name>.<container_network>.<default_domain>`, `<container_name>.<container_network>`
If a non-default network is used (not `bridge` or `host`) then a name will be generated based on the network's name: If a non-default network is used (not `bridge` or `host`) then a name will be generated based on the network's name:
```sh ```sh
...@@ -63,6 +63,20 @@ an exact match is required. If a generated domain address doesn't match the list ...@@ -63,6 +63,20 @@ an exact match is required. If a generated domain address doesn't match the list
docker run --rm -it --name db --network somenet alpine # db.somenet.docker docker run --rm -it --name db --network somenet alpine # db.somenet.docker
``` ```
4. `<service>.<project>.<default_domain>`, `<service>.<project>`,
`<container_number>.<service>.<project>.<default_domain>`, `<container_number>.<service>.<project>`
If `docker-compose` is then names will be generated based on the service and project's names. If a service has
multiple containers then the reply will contain all instances:
```sh
host webserver.someproject.docker # webserver.someproject.docker has address 172.16.238.3
# webserver.someproject.docker has address 172.16.238.4
host 1.webserver.someproject.docker # 1.webserver.someproject.docker has address 172.16.238.3
```
When the project's name is in the list of _allowed domains_ (`ALLOWED_DOMAINS=.docker,.someproject`), then the
`default_domain` will not be appended:
If configured correctly then `resolvectl status` should show the configured link-specific DNS server: If configured correctly then `resolvectl status` should show the configured link-specific DNS server:
$ resolvectl status $ resolvectl status
......
...@@ -49,7 +49,7 @@ class DockerWatcher(Thread): ...@@ -49,7 +49,7 @@ class DockerWatcher(Thread):
hostname = c.attrs['Config']['Hostname'] hostname = c.attrs['Config']['Hostname']
domain = c.attrs['Config'].get('Domainname') domain = c.attrs['Config'].get('Domainname')
# if no explicit --hostname is provided, than it will be the first 12 characters of the container_id. # if no explicit --hostname is provided, then it will be the first 12 characters of the container_id.
# In that case, the hostname can be ignored # In that case, the hostname can be ignored
if hostname != container_id[:12]: if hostname != container_id[:12]:
if len(domain) > 0: if len(domain) > 0:
...@@ -57,6 +57,18 @@ class DockerWatcher(Thread): ...@@ -57,6 +57,18 @@ class DockerWatcher(Thread):
else: else:
common_hostnames.append(hostname) common_hostnames.append(hostname)
# for docker-compose services service.project (.docker) names are created
if c.attrs['Config'].get('Labels') and c.attrs['Config']['Labels'].get('com.docker.compose.service') and \
c.attrs['Config']['Labels'].get('com.docker.compose.project'):
common_hostnames.append("%s.%s" % (c.attrs['Config']['Labels'].get('com.docker.compose.service'),
c.attrs['Config']['Labels'].get('com.docker.compose.project')))
if c.attrs['Config']['Labels'].get('com.docker.compose.container-number'):
common_hostnames.append("%s.%s.%s" % (c.attrs['Config']['Labels'].get('com.docker.compose.container-number'),
c.attrs['Config']['Labels'].get('com.docker.compose.service'),
c.attrs['Config']['Labels'].get(
'com.docker.compose.project')))
name = c.attrs['Name'][1:] name = c.attrs['Name'][1:]
settings = c.attrs['NetworkSettings'] settings = c.attrs['NetworkSettings']
for netname, network in settings.get('Networks', {}).items(): for netname, network in settings.get('Networks', {}).items():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment