Signed-off-by: Lei Jitang <leijitang@huawei.com>
| ... | ... |
@@ -224,6 +224,9 @@ func (cli *DaemonCli) CmdDaemon(args ...string) error {
|
| 224 | 224 |
defaultHost = opts.DefaultTLSHost |
| 225 | 225 |
} |
| 226 | 226 |
|
| 227 |
+ if len(commonFlags.Hosts) == 0 {
|
|
| 228 |
+ commonFlags.Hosts = make([]string, 1) |
|
| 229 |
+ } |
|
| 227 | 230 |
for i := 0; i < len(commonFlags.Hosts); i++ {
|
| 228 | 231 |
var err error |
| 229 | 232 |
if commonFlags.Hosts[i], err = opts.ParseHost(defaultHost, commonFlags.Hosts[i]); err != nil {
|
| ... | ... |
@@ -1715,3 +1715,11 @@ func (s *DockerDaemonSuite) TestDaemonCorruptedFluentdAddress(c *check.C) {
|
| 1715 | 1715 |
c.Fatalf("Expected %q message; but doesn't exist in log: %q, err: %v", expected, out, err)
|
| 1716 | 1716 |
} |
| 1717 | 1717 |
} |
| 1718 |
+ |
|
| 1719 |
+func (s *DockerDaemonSuite) TestDaemonStartWithoutHost(c *check.C) {
|
|
| 1720 |
+ s.d.useDefaultHost = true |
|
| 1721 |
+ defer func() {
|
|
| 1722 |
+ s.d.useDefaultHost = false |
|
| 1723 |
+ }() |
|
| 1724 |
+ c.Assert(s.d.Start(), check.IsNil) |
|
| 1725 |
+} |
| ... | ... |
@@ -49,6 +49,7 @@ type Daemon struct {
|
| 49 | 49 |
execDriver string |
| 50 | 50 |
wait chan error |
| 51 | 51 |
userlandProxy bool |
| 52 |
+ useDefaultHost bool |
|
| 52 | 53 |
} |
| 53 | 54 |
|
| 54 | 55 |
// NewDaemon returns a Daemon instance to be used for testing. |
| ... | ... |
@@ -101,12 +102,13 @@ func (d *Daemon) Start(arg ...string) error {
|
| 101 | 101 |
|
| 102 | 102 |
args := append(d.GlobalFlags, |
| 103 | 103 |
d.Command, |
| 104 |
- "--host", d.sock(), |
|
| 105 | 104 |
"--graph", d.root, |
| 106 | 105 |
"--pidfile", fmt.Sprintf("%s/docker.pid", d.folder),
|
| 107 | 106 |
fmt.Sprintf("--userland-proxy=%t", d.userlandProxy),
|
| 108 | 107 |
) |
| 109 |
- |
|
| 108 |
+ if !d.useDefaultHost {
|
|
| 109 |
+ args = append(args, []string{"--host", d.sock()}...)
|
|
| 110 |
+ } |
|
| 110 | 111 |
if root := os.Getenv("DOCKER_REMAP_ROOT"); root != "" {
|
| 111 | 112 |
args = append(args, []string{"--userns-remap", root}...)
|
| 112 | 113 |
} |
| ... | ... |
@@ -168,7 +170,15 @@ func (d *Daemon) Start(arg ...string) error {
|
| 168 | 168 |
case <-time.After(2 * time.Second): |
| 169 | 169 |
return fmt.Errorf("[%s] timeout: daemon does not respond", d.id)
|
| 170 | 170 |
case <-tick: |
| 171 |
- c, err := net.Dial("unix", filepath.Join(d.folder, "docker.sock"))
|
|
| 171 |
+ var ( |
|
| 172 |
+ c net.Conn |
|
| 173 |
+ err error |
|
| 174 |
+ ) |
|
| 175 |
+ if d.useDefaultHost {
|
|
| 176 |
+ c, err = net.Dial("unix", "/var/run/docker.sock")
|
|
| 177 |
+ } else {
|
|
| 178 |
+ c, err = net.Dial("unix", filepath.Join(d.folder, "docker.sock"))
|
|
| 179 |
+ } |
|
| 172 | 180 |
if err != nil {
|
| 173 | 181 |
continue |
| 174 | 182 |
} |
| ... | ... |
@@ -291,7 +301,15 @@ func (d *Daemon) Restart(arg ...string) error {
|
| 291 | 291 |
func (d *Daemon) queryRootDir() (string, error) {
|
| 292 | 292 |
// update daemon root by asking /info endpoint (to support user |
| 293 | 293 |
// namespaced daemon with root remapped uid.gid directory) |
| 294 |
- conn, err := net.Dial("unix", filepath.Join(d.folder, "docker.sock"))
|
|
| 294 |
+ var ( |
|
| 295 |
+ conn net.Conn |
|
| 296 |
+ err error |
|
| 297 |
+ ) |
|
| 298 |
+ if d.useDefaultHost {
|
|
| 299 |
+ conn, err = net.Dial("unix", "/var/run/docker.sock")
|
|
| 300 |
+ } else {
|
|
| 301 |
+ conn, err = net.Dial("unix", filepath.Join(d.folder, "docker.sock"))
|
|
| 302 |
+ } |
|
| 295 | 303 |
if err != nil {
|
| 296 | 304 |
return "", err |
| 297 | 305 |
} |