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
0ebc3e0a
Commit
0ebc3e0a
authored
3 years ago
by
Zsombor Welker
Browse files
Options
Downloads
Patches
Plain Diff
Add compose short names
This allows compose service names to be used without the project name.
parent
d9f35e03
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+6
-1
6 additions, 1 deletion
README.md
src/systemd_resolved_docker/dockerwatcher.py
+19
-7
19 additions, 7 deletions
src/systemd_resolved_docker/dockerwatcher.py
test/integration/test_compose.sh
+25
-3
25 additions, 3 deletions
test/integration/test_compose.sh
with
50 additions
and
11 deletions
README.md
+
6
−
1
View file @
0ebc3e0a
...
...
@@ -75,7 +75,12 @@ an exact match is required. If a generated domain address doesn't match the list
```
When the project's name is in the list of _allowed domains_ (
`ALLOWED_DOMAINS=.docker,.someproject`
), then the
`default_domain`
will not be appended:
`default_domain`
will not be appended.
If a
`<service>`
name is unique, then it is available also as
`<service>.<default_domain>`
.
```
host webserver.docker # webserver.docker has address 172.16.238.3
```
If configured correctly then
`resolvectl status`
should show the configured link-specific DNS server:
...
...
This diff is collapsed.
Click to expand it.
src/systemd_resolved_docker/dockerwatcher.py
+
19
−
7
View file @
0ebc3e0a
...
...
@@ -42,6 +42,9 @@ class DockerWatcher(Thread):
def
collect_from_containers
(
self
):
domain_records
=
{}
non_unique_hostnames
=
set
()
duplicate_hostnames
=
set
()
for
c
in
self
.
cli
.
containers
.
list
():
common_hostnames
=
[]
...
...
@@ -64,14 +67,20 @@ class DockerWatcher(Thread):
# 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
'
)))
compose_service
=
c
.
attrs
[
'
Config
'
][
'
Labels
'
].
get
(
'
com.docker.compose.service
'
)
compose_project
=
c
.
attrs
[
'
Config
'
][
'
Labels
'
].
get
(
'
com.docker.compose.project
'
)
common_hostnames
.
append
(
compose_service
)
common_hostnames
.
append
(
"
%s.%s
"
%
(
compose_service
,
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
'
)))
if
compose_service
in
non_unique_hostnames
:
duplicate_hostnames
.
add
(
compose_service
)
else
:
non_unique_hostnames
.
add
(
compose_service
)
compose_container_number
=
c
.
attrs
[
'
Config
'
][
'
Labels
'
].
get
(
'
com.docker.compose.container-number
'
)
if
compose_container_number
:
common_hostnames
.
append
(
"
%s.%s.%s
"
%
(
compose_container_number
,
compose_service
,
compose_project
))
name
=
c
.
attrs
[
'
Name
'
][
1
:]
settings
=
c
.
attrs
[
'
NetworkSettings
'
]
...
...
@@ -93,6 +102,9 @@ class DockerWatcher(Thread):
domain_records
[
ip
]
=
record
for
ip
,
hosts
in
domain_records
.
items
():
domain_records
[
ip
]
=
list
(
filter
(
lambda
h
:
h
not
in
duplicate_hostnames
,
hosts
))
hostnames
=
[
DockerHost
(
hosts
,
ip
)
for
ip
,
hosts
in
domain_records
.
items
()]
self
.
handler
.
handle_hosts
(
hostnames
)
...
...
This diff is collapsed.
Click to expand it.
test/integration/test_compose.sh
+
25
−
3
View file @
0ebc3e0a
...
...
@@ -26,9 +26,26 @@ networks:
-
$TEST_LABEL
ipam:
driver: default
config:
- subnet: 172.16.238.0/24
gateway: 172.16.238.1
EOF
exec
20
<<
EOF
version: "2.1"
services:
broker:
image: redis
labels:
-
$TEST_LABEL
networks:
- network
networks:
network:
driver: bridge
enable_ipv6: false
labels:
-
$TEST_LABEL
ipam:
driver: default
EOF
ALLOWED_DOMAINS
=
.docker,.
$TEST_PREFIX
start_systemd_resolved_docker
...
...
@@ -46,3 +63,8 @@ query_ok webserver.$TEST_PREFIX $webserver1_ip
query_ok webserver.
$TEST_PREFIX
$webserver2_ip
query_ok 1.webserver.
$TEST_PREFIX
$webserver1_ip
query_ok 2.webserver.
$TEST_PREFIX
$webserver2_ip
query_ok broker.docker
$broker1_ip
docker-compose
--file
/dev/fd/20
--project-name
${
TEST_PREFIX
}
_2 up
--detach
query_fail broker.docker
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