Browse code

Add insecure registries to docker info

Signed-off-by: Tomasz Kopczynski <tomek@kopczynski.net.pl>

Tomasz Kopczynski authored on 2016/02/17 07:45:48
Showing 4 changed files
... ...
@@ -151,5 +151,19 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
151 151
 	if info.ClusterAdvertise != "" {
152 152
 		fmt.Fprintf(cli.out, "Cluster Advertise: %s\n", info.ClusterAdvertise)
153 153
 	}
154
+
155
+	if info.RegistryConfig != nil && (len(info.RegistryConfig.InsecureRegistryCIDRs) > 0 || len(info.RegistryConfig.IndexConfigs) > 0) {
156
+		fmt.Fprintln(cli.out, "Insecure registries:")
157
+		for _, registry := range info.RegistryConfig.IndexConfigs {
158
+			if registry.Secure == false {
159
+				fmt.Fprintf(cli.out, " %s\n", registry.Name)
160
+			}
161
+		}
162
+
163
+		for _, registry := range info.RegistryConfig.InsecureRegistryCIDRs {
164
+			mask, _ := registry.Mask.Size()
165
+			fmt.Fprintf(cli.out, " %s/%d\n", registry.IP.String(), mask)
166
+		}
167
+	}
154 168
 	return nil
155 169
 }
... ...
@@ -62,6 +62,9 @@ For example:
62 62
     Registry: [https://index.docker.io/v1/]
63 63
     Labels:
64 64
      storage=ssd
65
+    Insecure registries:
66
+     myinsecurehost:5000
67
+     127.0.0.0/8
65 68
 
66 69
 The global `-D` option tells all `docker` commands to output debug information.
67 70
 
... ...
@@ -164,3 +164,21 @@ func (s *DockerSuite) TestInfoDebug(c *check.C) {
164 164
 	c.Assert(out, checker.Contains, "EventsListeners")
165 165
 	c.Assert(out, checker.Contains, "Docker Root Dir")
166 166
 }
167
+
168
+func (s *DockerSuite) TestInsecureRegistries(c *check.C) {
169
+	testRequires(c, SameHostDaemon, DaemonIsLinux)
170
+
171
+	registryCIDR := "192.168.1.0/24"
172
+	registryHost := "insecurehost.com:5000"
173
+
174
+	d := NewDaemon(c)
175
+	err := d.Start("--insecure-registry="+registryCIDR, "--insecure-registry="+registryHost)
176
+	c.Assert(err, checker.IsNil)
177
+	defer d.Stop()
178
+
179
+	out, err := d.Cmd("info")
180
+	c.Assert(err, checker.IsNil)
181
+	c.Assert(out, checker.Contains, "Insecure registries:\n")
182
+	c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryHost))
183
+	c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryCIDR))
184
+}
... ...
@@ -59,6 +59,9 @@ Here is a sample output:
59 59
     Debug mode (server): false
60 60
     Username: xyz
61 61
     Registry: https://index.docker.io/v1/
62
+    Insecure registries:
63
+     myinsecurehost:5000
64
+     127.0.0.0/8
62 65
 	
63 66
 # HISTORY
64 67
 April 2014, Originally compiled by William Henry (whenry at redhat dot com)