Browse code

Add registry mirrors information in the output of `docker info`

This fix tries to add the registry mirrors information in the output
of `docker info`.

In our active deployment, we use registry mirrors to help speeding
up the `docker pull`. In the current output of `docker info`,
registry mirrors is not present though it is available in `/info` API.

I think it makes sense to add the registry mirrors to `docker info`,
similiar to insecure registries.

This fix adds the registry mirrors to the output of `docker info`:
```
Registry Mirrors:
https://192.168.1.2/
http://registry.mirror.com:5000/
```

An integration test has been added to cover the changes.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

Yong Tang authored on 2016/08/30 03:50:11
Showing 2 changed files
... ...
@@ -237,6 +237,13 @@ func prettyPrintInfo(dockerCli *client.DockerCli, info types.Info) error {
237 237
 		}
238 238
 	}
239 239
 
240
+	if info.RegistryConfig != nil && len(info.RegistryConfig.Mirrors) > 0 {
241
+		fmt.Fprintln(dockerCli.Out(), "Registry Mirrors:")
242
+		for _, mirror := range info.RegistryConfig.Mirrors {
243
+			fmt.Fprintf(dockerCli.Out(), " %s\n", mirror)
244
+		}
245
+	}
246
+
240 247
 	fmt.Fprintf(dockerCli.Out(), "Live Restore Enabled: %v\n", info.LiveRestoreEnabled)
241 248
 
242 249
 	return nil
... ...
@@ -200,3 +200,19 @@ func (s *DockerSuite) TestInsecureRegistries(c *check.C) {
200 200
 	c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryHost))
201 201
 	c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryCIDR))
202 202
 }
203
+
204
+func (s *DockerDaemonSuite) TestRegistryMirrors(c *check.C) {
205
+	testRequires(c, SameHostDaemon, DaemonIsLinux)
206
+
207
+	registryMirror1 := "https://192.168.1.2"
208
+	registryMirror2 := "http://registry.mirror.com:5000"
209
+
210
+	err := s.d.Start("--registry-mirror="+registryMirror1, "--registry-mirror="+registryMirror2)
211
+	c.Assert(err, checker.IsNil)
212
+
213
+	out, err := s.d.Cmd("info")
214
+	c.Assert(err, checker.IsNil)
215
+	c.Assert(out, checker.Contains, "Registry Mirrors:\n")
216
+	c.Assert(out, checker.Contains, fmt.Sprintf(" %s", registryMirror1))
217
+	c.Assert(out, checker.Contains, fmt.Sprintf(" %s", registryMirror2))
218
+}