Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
systemd-resolved-docker
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
flaktack
systemd-resolved-docker
Commits
daf285f4
Commit
daf285f4
authored
3 years ago
by
Zsombor Welker
Browse files
Options
Downloads
Patches
Plain Diff
Generate names for docker-compose
parent
1ffe353f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+16
-2
16 additions, 2 deletions
README.md
src/systemd_resolved_docker/dockerwatcher.py
+13
-1
13 additions, 1 deletion
src/systemd_resolved_docker/dockerwatcher.py
with
29 additions
and
3 deletions
README.md
+
16
−
2
View file @
daf285f4
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
src/systemd_resolved_docker/dockerwatcher.py
+
13
−
1
View file @
daf285f4
...
@@ -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, th
a
n it will be the first 12 characters of the container_id.
# if no explicit --hostname is provided, th
e
n 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
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment