Skip to content

Commit

Permalink
Merge pull request #4 from kibatic/fix_net_host
Browse files Browse the repository at this point in the history
Fix net alias when network=host
  • Loading branch information
eliecharra authored Jun 30, 2017
2 parents d7f5099 + c50f5e8 commit e19e279
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion templates/default.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ ExecStart=/usr/bin/docker run {{ default_docker_options }}
{%- endfor %}
{%- endif %}
{% if unit.labels is defined %}{% for label in unit.labels %}--label {{ label }} {% endfor %}{% endif %}
{% if unit.links is not defined %} --network={{ unit.network|default(default_network_name) }} --net-alias={{ unit.net_alias|default(unit.name) }} {% endif %}
{%- if unit.links is not defined %}
{% set network = unit.network|default(default_network_name) %}
--network={{ network }}
{%- if network != "host" %} --net-alias={{ unit.net_alias|default(unit.name) }}{%- endif %}
{%- endif %}
{%- if unit.privileged is defined %}
--privileged
{%- endif %}
Expand Down
6 changes: 6 additions & 0 deletions tests/goss-systemd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ file:
filetype: file # file, symlink, directory
contains: # Check file content for these patterns
- "--add-host test:8.8.8.8"
# Cover https://github.com/kibatic/docker-systemd/issues/3
/lib/systemd/system/nginx-host.service:
exists: true
contains:
- "--network=host"
- "!--net-alias"
6 changes: 6 additions & 0 deletions tests/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ http:
timeout: 5000
body:
- Welcome to nginx!
http://localhost:
status: 200
timeout: 5000
body:
- Welcome to nginx!

command:
docker inspect nginx:
# required attributes
Expand Down
7 changes: 7 additions & 0 deletions tests/units/nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ systemd_units:
environment:
FOO: bar

# Cover https://github.com/kibatic/docker-systemd/issues/3
- name: nginx-host
template_name: templates/test-systemd
image: nginx:1.11
host_copy: []
network: host

default_docker_options: '--add-host test:8.8.8.8'

0 comments on commit e19e279

Please sign in to comment.