From 8958ea0f2d8ccc6b8f25c75b2030b9c2a325e975 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 15 Jan 2020 14:15:50 -0500 Subject: [PATCH] feat: add support for host-mode networking In host-mode, there is no 'bridge' network by default, so we return an invalid IP address of 'no value'. Instead, return '127.0.0.1' for those containers. --- plugins/network/network.go | 6 ++++++ tests/unit/20_network.bats | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/plugins/network/network.go b/plugins/network/network.go index be9b98a44..d5b671fd1 100644 --- a/plugins/network/network.go +++ b/plugins/network/network.go @@ -95,6 +95,12 @@ func GetContainerIpaddress(appName, processType, containerID string) (ipAddr str return } + if b, err := common.DockerInspect(containerID, "'{{ .HostConfig.NetworkMode }}'"); err == nil { + if string(b[:]) == "host" { + return "127.0.0.1" + } + } + b, err := common.DockerInspect(containerID, "'{{.NetworkSettings.Networks.bridge.IPAddress}}'") if err != nil || len(b) == 0 { // docker < 1.9 compatibility diff --git a/tests/unit/20_network.bats b/tests/unit/20_network.bats index 19e9dc118..8b54dc08a 100644 --- a/tests/unit/20_network.bats +++ b/tests/unit/20_network.bats @@ -67,3 +67,20 @@ assert_external_port() { assert_external_port $(< $CID_FILE) failure done } + +@test "(proxy) network host-mode" { + run /bin/bash -c "dokku docker-options:add $TEST_APP deploy \"--network=host\"" + echo "output: $output" + echo "status: $status" + assert_success + + run deploy_app + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "curl --silent --write-out '%{http_code}\n' `dokku url $TEST_APP` | grep 200" + echo "output: $output" + echo "status: $status" + assert_success +}