2014-02-25 16:17:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-04-18 02:24:19 +00:00
|
|
|
"strings"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
2015-10-16 21:48:51 +00:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-04-18 16:46:47 +00:00
|
|
|
"github.com/go-check/check"
|
2014-02-25 16:17:48 +00:00
|
|
|
)
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestCommitAfterContainerIsDone(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-14 06:35:36 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
dockerCmd(c, "wait", cleanedContainerID)
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
out, _ = dockerCmd(c, "commit", cleanedContainerID)
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedImageID := strings.TrimSpace(out)
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
dockerCmd(c, "inspect", cleanedImageID)
|
2014-06-08 06:37:31 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestCommitWithoutPause(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-14 06:35:36 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
|
2014-06-08 06:37:31 +00:00
|
|
|
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-06-08 06:37:31 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
dockerCmd(c, "wait", cleanedContainerID)
|
2014-06-08 06:37:31 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
out, _ = dockerCmd(c, "commit", "-p=false", cleanedContainerID)
|
2014-06-08 06:37:31 +00:00
|
|
|
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedImageID := strings.TrimSpace(out)
|
2014-06-08 06:37:31 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
dockerCmd(c, "inspect", cleanedImageID)
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
2014-04-18 02:24:19 +00:00
|
|
|
|
2015-02-24 11:28:40 +00:00
|
|
|
//test commit a paused container should not unpause it after commit
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-02-24 11:28:40 +00:00
|
|
|
defer unpauseAllContainers()
|
2015-07-14 06:35:36 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "-i", "-d", "busybox")
|
2015-02-24 11:28:40 +00:00
|
|
|
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2015-02-24 11:28:40 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
dockerCmd(c, "pause", cleanedContainerID)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "commit", cleanedContainerID)
|
2015-02-24 11:28:40 +00:00
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
out = inspectField(c, cleanedContainerID, "State.Paused")
|
2015-10-16 21:48:51 +00:00
|
|
|
// commit should not unpause a paused container
|
|
|
|
c.Assert(out, checker.Contains, "true")
|
2015-02-24 11:28:40 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestCommitNewFile(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-14 06:35:36 +00:00
|
|
|
dockerCmd(c, "run", "--name", "commiter", "busybox", "/bin/sh", "-c", "echo koye > /foo")
|
2014-04-18 02:24:19 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
imageID, _ := dockerCmd(c, "commit", "commiter")
|
2015-10-16 21:48:51 +00:00
|
|
|
imageID = strings.TrimSpace(imageID)
|
2014-04-18 02:24:19 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
out, _ := dockerCmd(c, "run", imageID, "cat", "/foo")
|
2015-10-16 21:48:51 +00:00
|
|
|
actual := strings.TrimSpace(out)
|
|
|
|
c.Assert(actual, checker.Equals, "koye")
|
2014-04-18 02:24:19 +00:00
|
|
|
}
|
2014-03-27 19:16:03 +00:00
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestCommitHardlink(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-14 06:35:36 +00:00
|
|
|
firstOutput, _ := dockerCmd(c, "run", "-t", "--name", "hardlinks", "busybox", "sh", "-c", "touch file1 && ln file1 file2 && ls -di file1 file2")
|
2014-09-15 18:45:53 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
chunks := strings.Split(strings.TrimSpace(firstOutput), " ")
|
2014-09-15 18:45:53 +00:00
|
|
|
inode := chunks[0]
|
2015-10-16 21:48:51 +00:00
|
|
|
chunks = strings.SplitAfterN(strings.TrimSpace(firstOutput), " ", 2)
|
|
|
|
c.Assert(chunks[1], checker.Contains, chunks[0], check.Commentf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]))
|
2014-09-15 18:45:53 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
imageID, _ := dockerCmd(c, "commit", "hardlinks", "hardlinks")
|
2015-10-16 21:48:51 +00:00
|
|
|
imageID = strings.TrimSpace(imageID)
|
2014-09-15 18:45:53 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
secondOutput, _ := dockerCmd(c, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2")
|
2014-09-15 18:45:53 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
chunks = strings.Split(strings.TrimSpace(secondOutput), " ")
|
2014-09-15 18:45:53 +00:00
|
|
|
inode = chunks[0]
|
2015-10-16 21:48:51 +00:00
|
|
|
chunks = strings.SplitAfterN(strings.TrimSpace(secondOutput), " ", 2)
|
|
|
|
c.Assert(chunks[1], checker.Contains, chunks[0], check.Commentf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]))
|
2014-09-15 18:45:53 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestCommitTTY(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-14 06:35:36 +00:00
|
|
|
dockerCmd(c, "run", "-t", "--name", "tty", "busybox", "/bin/ls")
|
2014-03-27 19:16:03 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
imageID, _ := dockerCmd(c, "commit", "tty", "ttytest")
|
2015-10-16 21:48:51 +00:00
|
|
|
imageID = strings.TrimSpace(imageID)
|
2014-03-27 19:16:03 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
dockerCmd(c, "run", "ttytest", "/bin/ls")
|
2014-03-27 19:16:03 +00:00
|
|
|
}
|
2014-05-19 22:57:29 +00:00
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-14 06:35:36 +00:00
|
|
|
dockerCmd(c, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true")
|
2014-10-14 18:26:53 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
imageID, _ := dockerCmd(c, "commit", "bind-commit", "bindtest")
|
2015-10-16 21:48:51 +00:00
|
|
|
imageID = strings.TrimSpace(imageID)
|
2014-05-19 22:57:29 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
dockerCmd(c, "run", "bindtest", "true")
|
2014-05-19 22:57:29 +00:00
|
|
|
}
|
2014-10-01 09:35:44 +00:00
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestCommitChange(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-14 06:35:36 +00:00
|
|
|
dockerCmd(c, "run", "--name", "test", "busybox", "true")
|
2015-02-05 11:26:05 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
imageID, _ := dockerCmd(c, "commit",
|
2014-10-01 09:35:44 +00:00
|
|
|
"--change", "EXPOSE 8080",
|
|
|
|
"--change", "ENV DEBUG true",
|
2015-01-12 19:52:44 +00:00
|
|
|
"--change", "ENV test 1",
|
2015-02-25 08:04:46 +00:00
|
|
|
"--change", "ENV PATH /foo",
|
2015-06-04 13:47:55 +00:00
|
|
|
"--change", "LABEL foo bar",
|
|
|
|
"--change", "CMD [\"/bin/sh\"]",
|
|
|
|
"--change", "WORKDIR /opt",
|
|
|
|
"--change", "ENTRYPOINT [\"/bin/sh\"]",
|
|
|
|
"--change", "USER testuser",
|
|
|
|
"--change", "VOLUME /var/lib/docker",
|
|
|
|
"--change", "ONBUILD /usr/local/bin/python-build --dir /app/src",
|
2014-10-01 09:35:44 +00:00
|
|
|
"test", "test-commit")
|
2015-10-16 21:48:51 +00:00
|
|
|
imageID = strings.TrimSpace(imageID)
|
2014-10-01 09:35:44 +00:00
|
|
|
|
|
|
|
expected := map[string]string{
|
2015-03-26 19:43:00 +00:00
|
|
|
"Config.ExposedPorts": "map[8080/tcp:{}]",
|
2015-02-25 08:04:46 +00:00
|
|
|
"Config.Env": "[DEBUG=true test=1 PATH=/foo]",
|
2015-06-04 13:47:55 +00:00
|
|
|
"Config.Labels": "map[foo:bar]",
|
2016-02-29 11:28:37 +00:00
|
|
|
"Config.Cmd": "[/bin/sh]",
|
2015-06-04 13:47:55 +00:00
|
|
|
"Config.WorkingDir": "/opt",
|
2016-02-29 11:28:37 +00:00
|
|
|
"Config.Entrypoint": "[/bin/sh]",
|
2015-06-04 13:47:55 +00:00
|
|
|
"Config.User": "testuser",
|
|
|
|
"Config.Volumes": "map[/var/lib/docker:{}]",
|
|
|
|
"Config.OnBuild": "[/usr/local/bin/python-build --dir /app/src]",
|
2014-10-01 09:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for conf, value := range expected {
|
2016-01-28 14:19:25 +00:00
|
|
|
res := inspectField(c, imageID, conf)
|
2014-10-01 09:35:44 +00:00
|
|
|
if res != value {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Errorf("%s('%s'), expected %s", conf, res, value)
|
2014-10-01 09:35:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-10 21:01:40 +00:00
|
|
|
|
|
|
|
// TODO: commit --run is deprecated, remove this once --run is removed
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestCommitMergeConfigRun(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-10 21:01:40 +00:00
|
|
|
name := "commit-test"
|
2015-04-18 16:46:47 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "-e=FOO=bar", "busybox", "/bin/sh", "-c", "echo testing > /tmp/foo")
|
2015-04-10 21:01:40 +00:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
dockerCmd(c, "commit", `--run={"Cmd": ["cat", "/tmp/foo"]}`, id, "commit-test")
|
2015-04-10 21:01:40 +00:00
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
out, _ = dockerCmd(c, "run", "--name", name, "commit-test")
|
2015-10-16 21:48:51 +00:00
|
|
|
//run config in committed container was not merged
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, "testing")
|
2015-04-10 21:01:40 +00:00
|
|
|
|
|
|
|
type cfg struct {
|
|
|
|
Env []string
|
|
|
|
Cmd []string
|
|
|
|
}
|
|
|
|
config1 := cfg{}
|
2016-01-28 14:19:25 +00:00
|
|
|
inspectFieldAndMarshall(c, id, "Config", &config1)
|
2015-10-16 21:48:51 +00:00
|
|
|
|
2015-04-10 21:01:40 +00:00
|
|
|
config2 := cfg{}
|
2016-01-28 14:19:25 +00:00
|
|
|
inspectFieldAndMarshall(c, name, "Config", &config2)
|
2015-04-10 21:01:40 +00:00
|
|
|
|
|
|
|
// Env has at least PATH loaded as well here, so let's just grab the FOO one
|
|
|
|
var env1, env2 string
|
|
|
|
for _, e := range config1.Env {
|
|
|
|
if strings.HasPrefix(e, "FOO") {
|
|
|
|
env1 = e
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, e := range config2.Env {
|
|
|
|
if strings.HasPrefix(e, "FOO") {
|
|
|
|
env2 = e
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(config1.Env) != len(config2.Env) || env1 != env2 && env2 != "" {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("expected envs to match: %v - %v", config1.Env, config2.Env)
|
2015-04-10 21:01:40 +00:00
|
|
|
}
|
|
|
|
}
|