mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-06 13:41:36 +00:00
Merge pull request #938 from dotcloud/add_unix_socket-feature
* Runtime: Add unix socket and multiple -H
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"index/suffixarray"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -652,3 +653,30 @@ func CheckLocalDns() bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ParseHost(host string, port int, addr string) string {
|
||||
if strings.HasPrefix(addr, "unix://") {
|
||||
return addr
|
||||
}
|
||||
if strings.HasPrefix(addr, "tcp://") {
|
||||
addr = strings.TrimPrefix(addr, "tcp://")
|
||||
}
|
||||
if strings.Contains(addr, ":") {
|
||||
hostParts := strings.Split(addr, ":")
|
||||
if len(hostParts) != 2 {
|
||||
log.Fatal("Invalid bind address format.")
|
||||
os.Exit(-1)
|
||||
}
|
||||
if hostParts[0] != "" {
|
||||
host = hostParts[0]
|
||||
}
|
||||
if p, err := strconv.Atoi(hostParts[1]); err == nil {
|
||||
port = p
|
||||
}
|
||||
} else {
|
||||
host = addr
|
||||
}
|
||||
return fmt.Sprintf("tcp://%s:%d", host, port)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -274,3 +274,21 @@ func TestHumanSize(t *testing.T) {
|
||||
t.Errorf("1024 -> expected 1.024 kB, got %s", size1024)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseHost(t *testing.T) {
|
||||
if addr := ParseHost("127.0.0.1", 4243, "0.0.0.0"); addr != "tcp://0.0.0.0:4243" {
|
||||
t.Errorf("0.0.0.0 -> expected tcp://0.0.0.0:4243, got %s", addr)
|
||||
}
|
||||
if addr := ParseHost("127.0.0.1", 4243, "0.0.0.1:5555"); addr != "tcp://0.0.0.1:5555" {
|
||||
t.Errorf("0.0.0.1:5555 -> expected tcp://0.0.0.1:5555, got %s", addr)
|
||||
}
|
||||
if addr := ParseHost("127.0.0.1", 4243, ":6666"); addr != "tcp://127.0.0.1:6666" {
|
||||
t.Errorf(":6666 -> expected tcp://127.0.0.1:6666, got %s", addr)
|
||||
}
|
||||
if addr := ParseHost("127.0.0.1", 4243, "tcp://:7777"); addr != "tcp://127.0.0.1:7777" {
|
||||
t.Errorf("tcp://:7777 -> expected tcp://127.0.0.1:7777, got %s", addr)
|
||||
}
|
||||
if addr := ParseHost("127.0.0.1", 4243, "unix:///var/run/docker.sock"); addr != "unix:///var/run/docker.sock" {
|
||||
t.Errorf("unix:///var/run/docker.sock -> expected unix:///var/run/docker.sock, got %s", addr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user