Skip to content

Commit 04dce29

Browse files
authored
Merge pull request #58 from andygrunwald/issue-57-add-host
Add support for `--add-host`
2 parents 584bf0e + fd4d50e commit 04dce29

4 files changed

Lines changed: 8 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Example of a Systemd unit for your app "myapp" that links to an already existing
2020
- '/data/uploads:/data/uploads'
2121
container_ports:
2222
- '3000:3000'
23+
container_hosts:
24+
- 'host.docker.internal:host-gateway'
2325
container_env:
2426
MYSQL_ROOT_PASSWORD: "{{ mysql_root_pw }}"
2527
container_labels:
@@ -46,6 +48,7 @@ This will create:
4648
* `container_volumes` (default: _[]_) - List of `-v` arguments
4749
* `container_host_network` (default: _false_) - Whether the host network should be used
4850
* `container_ports` (default: _[]_) - List of `-p` arguments
51+
* `container_hosts` (default: _[]_) - List of `--add-host` arguments
4952
* `container_links` (default: _[]_) - List of `--link` arguments
5053
* `container_labels` (default: _[]_) - List of `-l` arguments
5154
* `container_docker_pull` (default: _yes_) - whether the docker image should be pulled
@@ -87,7 +90,7 @@ and run `ansible-galaxy install -r requirements.yml`.
8790
## Gotchas
8891

8992
* When the unit or env file is changed, systemd gets reloaded but existing containers are NOT restarted.
90-
* Make sure to quote values for `container_ports`, `container_volumes` and so on, especially if they contain colons (`:`). Otherwise YAML will interpret them as hashes/maps and ansible will throw up.
93+
* Make sure to quote values for `container_ports`, `container_hosts`, `container_volumes` and so on, especially if they contain colons (`:`). Otherwise YAML will interpret them as hashes/maps and ansible will throw up.
9194

9295

9396
## About orchestrating Docker containers using systemd.

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ container_network: ""
99
container_user: ""
1010
container_links: []
1111
container_ports: []
12+
container_hosts: []
1213
container_volumes: []
1314
container_cap_add: []
1415
container_cap_drop: []

templates/unit.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ ExecStart={{ docker_path }} run \
3030
{% if container_network %}--network {{ container_network }}{% endif %} \
3131
{% if container_user %}--user {{ container_user }}{% endif %} \
3232
{{ params('--link', container_links) }}\
33+
{{ params('--add-host', container_hosts) }}\
3334
{{ params('--label', container_labels) }}\
3435
{{ params('--cap-add', container_cap_add) }}\
3536
{{ params('--cap-drop', container_cap_drop) }}\

tests/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
- '/data/uploads:/data/uploads'
1414
container_ports:
1515
- '3000:3000'
16+
container_hosts:
17+
- 'host.docker.internal:host-gateway'
1618
container_env:
1719
MYSQL_ROOT_PASSWORD: "very sekr1t"

0 commit comments

Comments
 (0)