From 428ae707599aa343aa058cb54c10bc65b50d5856 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Mon, 19 Dec 2016 09:56:20 -0800 Subject: [PATCH] commit: do not change container labels on commit Fix #29547 Signed-off-by: Alexander Morozov (cherry picked from commit ca6c6f0765aeccdb2730d03c05bd965906df8cd4) Signed-off-by: Victor Vieux --- daemon/commit.go | 7 +++---- integration-cli/docker_cli_commit_test.go | 13 +++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/daemon/commit.go b/daemon/commit.go index 333f7f2f93..1e7bffb1dc 100644 --- a/daemon/commit.go +++ b/daemon/commit.go @@ -65,11 +65,10 @@ func merge(userConf, imageConf *containertypes.Config) error { if userConf.Labels == nil { userConf.Labels = map[string]string{} } - if imageConf.Labels != nil { - for l := range userConf.Labels { - imageConf.Labels[l] = userConf.Labels[l] + for l, v := range imageConf.Labels { + if _, ok := userConf.Labels[l]; !ok { + userConf.Labels[l] = v } - userConf.Labels = imageConf.Labels } if len(userConf.Entrypoint) == 0 { diff --git a/integration-cli/docker_cli_commit_test.go b/integration-cli/docker_cli_commit_test.go index 72ff89f3dc..8008ae1716 100644 --- a/integration-cli/docker_cli_commit_test.go +++ b/integration-cli/docker_cli_commit_test.go @@ -142,3 +142,16 @@ func (s *DockerSuite) TestCommitChange(c *check.C) { } } } + +func (s *DockerSuite) TestCommitChangeLabels(c *check.C) { + dockerCmd(c, "run", "--name", "test", "--label", "some=label", "busybox", "true") + + imageID, _ := dockerCmd(c, "commit", + "--change", "LABEL some=label2", + "test", "test-commit") + imageID = strings.TrimSpace(imageID) + + c.Assert(inspectField(c, imageID, "Config.Labels"), checker.Equals, "map[some:label2]") + // check that container labels didn't change + c.Assert(inspectField(c, "test", "Config.Labels"), checker.Equals, "map[some:label]") +}