Browse code

commit: do not change container labels on commit

Fix #29547

Signed-off-by: Alexander Morozov <lk4d4@docker.com>

Alexander Morozov authored on 2016/12/20 02:56:20
Showing 2 changed files
... ...
@@ -65,11 +65,10 @@ func merge(userConf, imageConf *containertypes.Config) error {
65 65
 	if userConf.Labels == nil {
66 66
 		userConf.Labels = map[string]string{}
67 67
 	}
68
-	if imageConf.Labels != nil {
69
-		for l := range userConf.Labels {
70
-			imageConf.Labels[l] = userConf.Labels[l]
68
+	for l, v := range imageConf.Labels {
69
+		if _, ok := userConf.Labels[l]; !ok {
70
+			userConf.Labels[l] = v
71 71
 		}
72
-		userConf.Labels = imageConf.Labels
73 72
 	}
74 73
 
75 74
 	if len(userConf.Entrypoint) == 0 {
... ...
@@ -142,3 +142,16 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
142 142
 		}
143 143
 	}
144 144
 }
145
+
146
+func (s *DockerSuite) TestCommitChangeLabels(c *check.C) {
147
+	dockerCmd(c, "run", "--name", "test", "--label", "some=label", "busybox", "true")
148
+
149
+	imageID, _ := dockerCmd(c, "commit",
150
+		"--change", "LABEL some=label2",
151
+		"test", "test-commit")
152
+	imageID = strings.TrimSpace(imageID)
153
+
154
+	c.Assert(inspectField(c, imageID, "Config.Labels"), checker.Equals, "map[some:label2]")
155
+	// check that container labels didn't change
156
+	c.Assert(inspectField(c, "test", "Config.Labels"), checker.Equals, "map[some:label]")
157
+}