Signed-off-by: Lei Jitang <leijitang@huawei.com>
| ... | ... |
@@ -41,7 +41,7 @@ func (daemon *Daemon) ContainerCommit(job *engine.Job) engine.Status {
|
| 41 | 41 |
// Commit creates a new filesystem image from the current state of a container. |
| 42 | 42 |
// The image can optionally be tagged into a repository |
| 43 | 43 |
func (daemon *Daemon) Commit(container *Container, repository, tag, comment, author string, pause bool, config *runconfig.Config) (*image.Image, error) {
|
| 44 |
- if pause {
|
|
| 44 |
+ if pause && !container.IsPaused() {
|
|
| 45 | 45 |
container.Pause() |
| 46 | 46 |
defer container.Unpause() |
| 47 | 47 |
} |
| ... | ... |
@@ -72,6 +72,44 @@ func TestCommitWithoutPause(t *testing.T) {
|
| 72 | 72 |
logDone("commit - echo foo and commit the image with --pause=false")
|
| 73 | 73 |
} |
| 74 | 74 |
|
| 75 |
+//test commit a paused container should not unpause it after commit |
|
| 76 |
+func TestCommitPausedContainer(t *testing.T) {
|
|
| 77 |
+ defer deleteAllContainers() |
|
| 78 |
+ defer unpauseAllContainers() |
|
| 79 |
+ cmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox") |
|
| 80 |
+ out, _, _, err := runCommandWithStdoutStderr(cmd) |
|
| 81 |
+ if err != nil {
|
|
| 82 |
+ t.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 83 |
+ } |
|
| 84 |
+ |
|
| 85 |
+ cleanedContainerID := stripTrailingCharacters(out) |
|
| 86 |
+ cmd = exec.Command(dockerBinary, "pause", cleanedContainerID) |
|
| 87 |
+ out, _, _, err = runCommandWithStdoutStderr(cmd) |
|
| 88 |
+ if err != nil {
|
|
| 89 |
+ t.Fatalf("failed to pause container: %v, output: %q", err, out)
|
|
| 90 |
+ } |
|
| 91 |
+ |
|
| 92 |
+ commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID) |
|
| 93 |
+ out, _, err = runCommandWithOutput(commitCmd) |
|
| 94 |
+ if err != nil {
|
|
| 95 |
+ t.Fatalf("failed to commit container to image: %s, %v", out, err)
|
|
| 96 |
+ } |
|
| 97 |
+ cleanedImageID := stripTrailingCharacters(out) |
|
| 98 |
+ defer deleteImages(cleanedImageID) |
|
| 99 |
+ |
|
| 100 |
+ cmd = exec.Command(dockerBinary, "inspect", "-f", "{{.State.Paused}}", cleanedContainerID)
|
|
| 101 |
+ out, _, _, err = runCommandWithStdoutStderr(cmd) |
|
| 102 |
+ if err != nil {
|
|
| 103 |
+ t.Fatalf("failed to inspect container: %v, output: %q", err, out)
|
|
| 104 |
+ } |
|
| 105 |
+ |
|
| 106 |
+ if !strings.Contains(out, "true") {
|
|
| 107 |
+ t.Fatalf("commit should not unpause a paused container")
|
|
| 108 |
+ } |
|
| 109 |
+ |
|
| 110 |
+ logDone("commit - commit a paused container will not unpause it")
|
|
| 111 |
+} |
|
| 112 |
+ |
|
| 75 | 113 |
func TestCommitNewFile(t *testing.T) {
|
| 76 | 114 |
defer deleteAllContainers() |
| 77 | 115 |
|