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.
This commit is contained in:
Jose Diaz-Gonzalez
2020-01-15 14:15:50 -05:00
parent 7dd4efad39
commit 8958ea0f2d
2 changed files with 23 additions and 0 deletions

View File

@@ -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

View File

@@ -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
}