From 7c7c7f84dcc985dfac5aac5004d39d15e35f7812 Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Tue, 24 Feb 2015 03:28:40 -0800 Subject: [PATCH] Fix docker commit make a paused container to unpaused. Closes #10932 Signed-off-by: Lei Jitang --- daemon/commit.go | 2 +- integration-cli/docker_cli_commit_test.go | 38 +++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/daemon/commit.go b/daemon/commit.go index 7c83c60cc4..9d6d89a00b 100644 --- a/daemon/commit.go +++ b/daemon/commit.go @@ -41,7 +41,7 @@ func (daemon *Daemon) ContainerCommit(job *engine.Job) engine.Status { // Commit creates a new filesystem image from the current state of a container. // The image can optionally be tagged into a repository func (daemon *Daemon) Commit(container *Container, repository, tag, comment, author string, pause bool, config *runconfig.Config) (*image.Image, error) { - if pause { + if pause && !container.IsPaused() { container.Pause() defer container.Unpause() } diff --git a/integration-cli/docker_cli_commit_test.go b/integration-cli/docker_cli_commit_test.go index 18eca54444..5f3c6363a3 100644 --- a/integration-cli/docker_cli_commit_test.go +++ b/integration-cli/docker_cli_commit_test.go @@ -72,6 +72,44 @@ func TestCommitWithoutPause(t *testing.T) { logDone("commit - echo foo and commit the image with --pause=false") } +//test commit a paused container should not unpause it after commit +func TestCommitPausedContainer(t *testing.T) { + defer deleteAllContainers() + defer unpauseAllContainers() + cmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox") + out, _, _, err := runCommandWithStdoutStderr(cmd) + if err != nil { + t.Fatalf("failed to run container: %v, output: %q", err, out) + } + + cleanedContainerID := stripTrailingCharacters(out) + cmd = exec.Command(dockerBinary, "pause", cleanedContainerID) + out, _, _, err = runCommandWithStdoutStderr(cmd) + if err != nil { + t.Fatalf("failed to pause container: %v, output: %q", err, out) + } + + commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID) + out, _, err = runCommandWithOutput(commitCmd) + if err != nil { + t.Fatalf("failed to commit container to image: %s, %v", out, err) + } + cleanedImageID := stripTrailingCharacters(out) + defer deleteImages(cleanedImageID) + + cmd = exec.Command(dockerBinary, "inspect", "-f", "{{.State.Paused}}", cleanedContainerID) + out, _, _, err = runCommandWithStdoutStderr(cmd) + if err != nil { + t.Fatalf("failed to inspect container: %v, output: %q", err, out) + } + + if !strings.Contains(out, "true") { + t.Fatalf("commit should not unpause a paused container") + } + + logDone("commit - commit a paused container will not unpause it") +} + func TestCommitNewFile(t *testing.T) { defer deleteAllContainers()