2014-05-09 06:32:19 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2015-05-22 19:15:14 -04:00
|
|
|
"fmt"
|
2017-01-05 13:08:24 -05:00
|
|
|
"io/ioutil"
|
2014-11-11 11:17:33 -05:00
|
|
|
"os"
|
2015-01-06 19:04:10 -05:00
|
|
|
"reflect"
|
2015-04-06 09:21:18 -04:00
|
|
|
"strings"
|
2014-05-09 06:32:19 -04:00
|
|
|
"time"
|
2015-02-25 23:16:44 -05:00
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2017-04-10 08:42:21 -04:00
|
|
|
"github.com/docker/docker/integration-cli/cli"
|
2017-03-23 13:35:22 -04:00
|
|
|
"github.com/docker/docker/integration-cli/cli/build"
|
2017-04-10 08:42:21 -04:00
|
|
|
"github.com/docker/docker/integration-cli/cli/build/fakecontext"
|
2015-11-18 17:20:54 -05:00
|
|
|
"github.com/docker/docker/pkg/stringid"
|
2015-12-18 12:58:48 -05:00
|
|
|
"github.com/docker/go-connections/nat"
|
2015-04-18 12:46:47 -04:00
|
|
|
"github.com/go-check/check"
|
2017-08-23 17:01:29 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/icmd"
|
2014-05-09 06:32:19 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Make sure we can create a simple container with some args
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestCreateArgs(c *check.C) {
|
2016-10-07 20:50:42 -04:00
|
|
|
// Intentionally clear entrypoint, as the Windows busybox image needs an entrypoint, which breaks this test
|
|
|
|
out, _ := dockerCmd(c, "create", "--entrypoint=", "busybox", "command", "arg1", "arg2", "arg with space", "-c", "flags")
|
2014-05-09 06:32:19 -04:00
|
|
|
|
2015-04-06 09:21:18 -04:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-05-09 06:32:19 -04:00
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _ = dockerCmd(c, "inspect", cleanedContainerID)
|
2014-05-09 06:32:19 -04:00
|
|
|
|
|
|
|
containers := []struct {
|
|
|
|
ID string
|
|
|
|
Created time.Time
|
|
|
|
Path string
|
|
|
|
Args []string
|
|
|
|
Image string
|
|
|
|
}{}
|
2015-11-02 23:24:12 -05:00
|
|
|
|
|
|
|
err := json.Unmarshal([]byte(out), &containers)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
|
|
|
|
c.Assert(containers, checker.HasLen, 1)
|
2014-05-09 06:32:19 -04:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
cont := containers[0]
|
2015-11-02 23:24:12 -05:00
|
|
|
c.Assert(string(cont.Path), checker.Equals, "command", check.Commentf("Unexpected container path. Expected command, received: %s", cont.Path))
|
2014-05-09 06:32:19 -04:00
|
|
|
|
|
|
|
b := false
|
2016-06-07 08:11:11 -04:00
|
|
|
expected := []string{"arg1", "arg2", "arg with space", "-c", "flags"}
|
2014-05-09 06:32:19 -04:00
|
|
|
for i, arg := range expected {
|
2015-04-18 12:46:47 -04:00
|
|
|
if arg != cont.Args[i] {
|
2014-05-09 06:32:19 -04:00
|
|
|
b = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2015-04-18 12:46:47 -04:00
|
|
|
if len(cont.Args) != len(expected) || b {
|
|
|
|
c.Fatalf("Unexpected args. Expected %v, received: %v", expected, cont.Args)
|
2014-05-09 06:32:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-20 00:42:58 -04:00
|
|
|
// Make sure we can grow the container's rootfs at creation time.
|
|
|
|
func (s *DockerSuite) TestCreateGrowRootfs(c *check.C) {
|
2016-10-07 20:50:42 -04:00
|
|
|
// Windows and Devicemapper support growing the rootfs
|
2017-01-13 11:23:28 -05:00
|
|
|
if testEnv.DaemonPlatform() != "windows" {
|
2016-10-07 20:50:42 -04:00
|
|
|
testRequires(c, Devicemapper)
|
|
|
|
}
|
2016-03-20 00:42:58 -04:00
|
|
|
out, _ := dockerCmd(c, "create", "--storage-opt", "size=120G", "busybox")
|
|
|
|
|
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
inspectOut := inspectField(c, cleanedContainerID, "HostConfig.StorageOpt")
|
2016-04-01 02:52:29 -04:00
|
|
|
c.Assert(inspectOut, checker.Equals, "map[size:120G]")
|
2016-03-20 00:42:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we cannot shrink the container's rootfs at creation time.
|
|
|
|
func (s *DockerSuite) TestCreateShrinkRootfs(c *check.C) {
|
|
|
|
testRequires(c, Devicemapper)
|
|
|
|
|
2016-04-01 02:52:29 -04:00
|
|
|
// Ensure this fails because of the defaultBaseFsSize is 10G
|
|
|
|
out, _, err := dockerCmdWithError("create", "--storage-opt", "size=5G", "busybox")
|
2016-03-20 00:42:58 -04:00
|
|
|
c.Assert(err, check.NotNil, check.Commentf(out))
|
|
|
|
c.Assert(out, checker.Contains, "Container size cannot be smaller than")
|
|
|
|
}
|
|
|
|
|
2014-05-09 06:32:19 -04:00
|
|
|
// Make sure we can set hostconfig options too
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestCreateHostConfig(c *check.C) {
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _ := dockerCmd(c, "create", "-P", "busybox", "echo")
|
2014-05-09 06:32:19 -04:00
|
|
|
|
2015-04-06 09:21:18 -04:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-05-09 06:32:19 -04:00
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _ = dockerCmd(c, "inspect", cleanedContainerID)
|
2014-05-09 06:32:19 -04:00
|
|
|
|
|
|
|
containers := []struct {
|
|
|
|
HostConfig *struct {
|
|
|
|
PublishAllPorts bool
|
|
|
|
}
|
|
|
|
}{}
|
|
|
|
|
2015-11-02 23:24:12 -05:00
|
|
|
err := json.Unmarshal([]byte(out), &containers)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
|
|
|
|
c.Assert(containers, checker.HasLen, 1)
|
2014-05-09 06:32:19 -04:00
|
|
|
|
2015-11-02 23:24:12 -05:00
|
|
|
cont := containers[0]
|
|
|
|
c.Assert(cont.HostConfig, check.NotNil, check.Commentf("Expected HostConfig, got none"))
|
|
|
|
c.Assert(cont.HostConfig.PublishAllPorts, check.NotNil, check.Commentf("Expected PublishAllPorts, got false"))
|
2014-05-09 06:32:19 -04:00
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestCreateWithPortRange(c *check.C) {
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _ := dockerCmd(c, "create", "-p", "3300-3303:3300-3303/tcp", "busybox", "echo")
|
2014-11-03 13:15:55 -05:00
|
|
|
|
2015-04-06 09:21:18 -04:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-11-03 13:15:55 -05:00
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _ = dockerCmd(c, "inspect", cleanedContainerID)
|
2014-11-03 13:15:55 -05:00
|
|
|
|
|
|
|
containers := []struct {
|
|
|
|
HostConfig *struct {
|
|
|
|
PortBindings map[nat.Port][]nat.PortBinding
|
|
|
|
}
|
|
|
|
}{}
|
2015-11-02 23:24:12 -05:00
|
|
|
err := json.Unmarshal([]byte(out), &containers)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
|
|
|
|
c.Assert(containers, checker.HasLen, 1)
|
2014-11-03 13:15:55 -05:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
cont := containers[0]
|
2014-11-03 13:15:55 -05:00
|
|
|
|
2015-11-02 23:24:12 -05:00
|
|
|
c.Assert(cont.HostConfig, check.NotNil, check.Commentf("Expected HostConfig, got none"))
|
|
|
|
c.Assert(cont.HostConfig.PortBindings, checker.HasLen, 4, check.Commentf("Expected 4 ports bindings, got %d", len(cont.HostConfig.PortBindings)))
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
for k, v := range cont.HostConfig.PortBindings {
|
2015-11-02 23:24:12 -05:00
|
|
|
c.Assert(v, checker.HasLen, 1, check.Commentf("Expected 1 ports binding, for the port %s but found %s", k, v))
|
|
|
|
c.Assert(k.Port(), checker.Equals, v[0].HostPort, check.Commentf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
|
|
|
|
|
2014-11-03 13:15:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-02 19:00:39 -05:00
|
|
|
func (s *DockerSuite) TestCreateWithLargePortRange(c *check.C) {
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _ := dockerCmd(c, "create", "-p", "1-65535:1-65535/tcp", "busybox", "echo")
|
2014-11-03 13:15:55 -05:00
|
|
|
|
2015-04-06 09:21:18 -04:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-11-03 13:15:55 -05:00
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _ = dockerCmd(c, "inspect", cleanedContainerID)
|
2014-11-03 13:15:55 -05:00
|
|
|
|
|
|
|
containers := []struct {
|
|
|
|
HostConfig *struct {
|
|
|
|
PortBindings map[nat.Port][]nat.PortBinding
|
|
|
|
}
|
|
|
|
}{}
|
2015-11-02 23:24:12 -05:00
|
|
|
|
|
|
|
err := json.Unmarshal([]byte(out), &containers)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
|
|
|
|
c.Assert(containers, checker.HasLen, 1)
|
2014-11-03 13:15:55 -05:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
cont := containers[0]
|
2015-11-02 23:24:12 -05:00
|
|
|
c.Assert(cont.HostConfig, check.NotNil, check.Commentf("Expected HostConfig, got none"))
|
|
|
|
c.Assert(cont.HostConfig.PortBindings, checker.HasLen, 65535)
|
2014-11-03 13:15:55 -05:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
for k, v := range cont.HostConfig.PortBindings {
|
2015-11-02 23:24:12 -05:00
|
|
|
c.Assert(v, checker.HasLen, 1)
|
|
|
|
c.Assert(k.Port(), checker.Equals, v[0].HostPort, check.Commentf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
|
2014-11-03 13:15:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-09 06:32:19 -04:00
|
|
|
// "test123" should be printed by docker create + start
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestCreateEchoStdout(c *check.C) {
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _ := dockerCmd(c, "create", "busybox", "echo", "test123")
|
2014-05-09 06:32:19 -04:00
|
|
|
|
2015-04-06 09:21:18 -04:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-05-09 06:32:19 -04:00
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _ = dockerCmd(c, "start", "-ai", cleanedContainerID)
|
2015-11-02 23:24:12 -05:00
|
|
|
c.Assert(out, checker.Equals, "test123\n", check.Commentf("container should've printed 'test123', got %q", out))
|
2014-05-09 06:32:19 -04:00
|
|
|
|
|
|
|
}
|
2014-11-11 11:17:33 -05:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestCreateVolumesCreated(c *check.C) {
|
|
|
|
testRequires(c, SameHostDaemon)
|
2016-10-07 20:50:42 -04:00
|
|
|
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
2015-02-20 01:56:02 -05:00
|
|
|
|
2014-11-11 11:17:33 -05:00
|
|
|
name := "test_create_volume"
|
2016-10-07 20:50:42 -04:00
|
|
|
dockerCmd(c, "create", "--name", name, "-v", prefix+slash+"foo", "busybox")
|
2015-07-14 02:35:36 -04:00
|
|
|
|
2016-10-07 20:50:42 -04:00
|
|
|
dir, err := inspectMountSourceField(name, prefix+slash+"foo")
|
2015-11-02 23:24:12 -05:00
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Error getting volume host path: %q", err))
|
2014-11-11 11:17:33 -05:00
|
|
|
|
|
|
|
if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Volume was not created")
|
2014-11-11 11:17:33 -05:00
|
|
|
}
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error statting volume host path: %q", err)
|
2014-11-11 11:17:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-01-06 19:04:10 -05:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestCreateLabels(c *check.C) {
|
2015-01-06 19:04:10 -05:00
|
|
|
name := "test_create_labels"
|
|
|
|
expected := map[string]string{"k1": "v1", "k2": "v2"}
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, "create", "--name", name, "-l", "k1=v1", "--label", "k2=v2", "busybox")
|
2015-01-06 19:04:10 -05:00
|
|
|
|
|
|
|
actual := make(map[string]string)
|
2017-01-10 13:16:25 -05:00
|
|
|
inspectFieldAndUnmarshall(c, name, "Config.Labels", &actual)
|
2015-01-06 19:04:10 -05:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(expected, actual) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Expected %s got %s", expected, actual)
|
2015-01-06 19:04:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestCreateLabelFromImage(c *check.C) {
|
2015-01-06 19:04:10 -05:00
|
|
|
imageName := "testcreatebuildlabel"
|
2017-03-23 13:35:22 -04:00
|
|
|
buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox
|
2017-01-16 05:30:14 -05:00
|
|
|
LABEL k1=v1 k2=v2`))
|
2015-01-06 19:04:10 -05:00
|
|
|
|
|
|
|
name := "test_create_labels_from_image"
|
2015-08-11 19:48:41 -04:00
|
|
|
expected := map[string]string{"k2": "x", "k3": "v3", "k1": "v1"}
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, "create", "--name", name, "-l", "k2=x", "--label", "k3=v3", imageName)
|
2015-01-06 19:04:10 -05:00
|
|
|
|
|
|
|
actual := make(map[string]string)
|
2017-01-10 13:16:25 -05:00
|
|
|
inspectFieldAndUnmarshall(c, name, "Config.Labels", &actual)
|
2015-01-06 19:04:10 -05:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(expected, actual) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Expected %s got %s", expected, actual)
|
2015-01-06 19:04:10 -05:00
|
|
|
}
|
|
|
|
}
|
2015-04-10 17:06:43 -04:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestCreateHostnameWithNumber(c *check.C) {
|
2016-10-07 20:50:42 -04:00
|
|
|
image := "busybox"
|
|
|
|
// Busybox on Windows does not implement hostname command
|
2017-01-13 11:23:28 -05:00
|
|
|
if testEnv.DaemonPlatform() == "windows" {
|
|
|
|
image = testEnv.MinimalBaseImage()
|
2016-10-07 20:50:42 -04:00
|
|
|
}
|
|
|
|
out, _ := dockerCmd(c, "run", "-h", "web.0", image, "hostname")
|
2015-11-02 23:24:12 -05:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, "web.0", check.Commentf("hostname not set, expected `web.0`, got: %s", out))
|
|
|
|
|
2015-04-10 17:06:43 -04:00
|
|
|
}
|
2015-05-21 10:30:51 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestCreateRM(c *check.C) {
|
|
|
|
// Test to make sure we can 'rm' a new container that is in
|
|
|
|
// "Created" state, and has ever been run. Test "rm -f" too.
|
|
|
|
|
|
|
|
// create a container
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _ := dockerCmd(c, "create", "busybox")
|
2015-05-21 10:30:51 -04:00
|
|
|
cID := strings.TrimSpace(out)
|
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, "rm", cID)
|
2015-05-21 10:30:51 -04:00
|
|
|
|
|
|
|
// Now do it again so we can "rm -f" this time
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _ = dockerCmd(c, "create", "busybox")
|
2015-05-21 10:30:51 -04:00
|
|
|
|
|
|
|
cID = strings.TrimSpace(out)
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, "rm", "-f", cID)
|
2015-05-21 10:30:51 -04:00
|
|
|
}
|
2015-05-22 19:15:14 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestCreateModeIpcContainer(c *check.C) {
|
2016-02-02 19:00:39 -05:00
|
|
|
// Uses Linux specific functionality (--ipc)
|
2016-03-23 09:37:15 -04:00
|
|
|
testRequires(c, DaemonIsLinux, SameHostDaemon)
|
2015-05-22 19:15:14 -04:00
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _ := dockerCmd(c, "create", "busybox")
|
2015-05-22 19:15:14 -04:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, "create", fmt.Sprintf("--ipc=container:%s", id), "busybox")
|
2015-05-22 19:15:14 -04:00
|
|
|
}
|
2015-07-22 12:14:48 -04:00
|
|
|
|
2015-11-18 17:20:54 -05:00
|
|
|
func (s *DockerSuite) TestCreateByImageID(c *check.C) {
|
|
|
|
imageName := "testcreatebyimageid"
|
2017-03-23 13:35:22 -04:00
|
|
|
buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox
|
2017-01-16 05:30:14 -05:00
|
|
|
MAINTAINER dockerio`))
|
|
|
|
imageID := getIDByName(c, imageName)
|
2015-11-18 17:20:54 -05:00
|
|
|
truncatedImageID := stringid.TruncateID(imageID)
|
|
|
|
|
|
|
|
dockerCmd(c, "create", imageID)
|
|
|
|
dockerCmd(c, "create", truncatedImageID)
|
|
|
|
dockerCmd(c, "create", fmt.Sprintf("%s:%s", imageName, truncatedImageID))
|
|
|
|
|
|
|
|
// Ensure this fails
|
|
|
|
out, exit, _ := dockerCmdWithError("create", fmt.Sprintf("%s:%s", imageName, imageID))
|
|
|
|
if exit == 0 {
|
|
|
|
c.Fatalf("expected non-zero exit code; received %d", exit)
|
|
|
|
}
|
|
|
|
|
2017-01-11 16:54:52 -05:00
|
|
|
if expected := "invalid reference format"; !strings.Contains(out, expected) {
|
2015-11-18 17:20:54 -05:00
|
|
|
c.Fatalf(`Expected %q in output; got: %s`, expected, out)
|
|
|
|
}
|
|
|
|
|
|
|
|
out, exit, _ = dockerCmdWithError("create", fmt.Sprintf("%s:%s", "wrongimage", truncatedImageID))
|
|
|
|
if exit == 0 {
|
|
|
|
c.Fatalf("expected non-zero exit code; received %d", exit)
|
|
|
|
}
|
|
|
|
|
|
|
|
if expected := "Unable to find image"; !strings.Contains(out, expected) {
|
|
|
|
c.Fatalf(`Expected %q in output; got: %s`, expected, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 12:14:48 -04:00
|
|
|
func (s *DockerTrustSuite) TestTrustedCreate(c *check.C) {
|
2015-07-23 08:12:36 -04:00
|
|
|
repoName := s.setupTrustedImage(c, "trusted-create")
|
2015-07-22 12:14:48 -04:00
|
|
|
|
|
|
|
// Try create
|
2017-04-19 08:04:39 -04:00
|
|
|
cli.Docker(cli.Args("create", repoName), trustedCmd).Assert(c, SuccessTagging)
|
|
|
|
cli.DockerCmd(c, "rmi", repoName)
|
2015-07-22 12:14:48 -04:00
|
|
|
|
|
|
|
// Try untrusted create to ensure we pushed the tag to the registry
|
2017-04-19 08:04:39 -04:00
|
|
|
cli.Docker(cli.Args("create", "--disable-content-trust=true", repoName)).Assert(c, SuccessDownloadedOnStderr)
|
2015-07-22 12:14:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerTrustSuite) TestUntrustedCreate(c *check.C) {
|
2016-01-26 20:52:36 -05:00
|
|
|
repoName := fmt.Sprintf("%v/dockercliuntrusted/createtest", privateRegistryURL)
|
|
|
|
withTagName := fmt.Sprintf("%s:latest", repoName)
|
2015-07-22 12:14:48 -04:00
|
|
|
// tag the image and upload it to the private registry
|
2017-04-19 08:04:39 -04:00
|
|
|
cli.DockerCmd(c, "tag", "busybox", withTagName)
|
|
|
|
cli.DockerCmd(c, "push", withTagName)
|
|
|
|
cli.DockerCmd(c, "rmi", withTagName)
|
2015-07-22 12:14:48 -04:00
|
|
|
|
|
|
|
// Try trusted create on untrusted tag
|
2017-04-19 08:04:39 -04:00
|
|
|
cli.Docker(cli.Args("create", withTagName), trustedCmd).Assert(c, icmd.Expected{
|
2017-01-05 13:08:24 -05:00
|
|
|
ExitCode: 1,
|
|
|
|
Err: fmt.Sprintf("does not have trust data for %s", repoName),
|
|
|
|
})
|
2015-07-22 12:14:48 -04:00
|
|
|
}
|
|
|
|
|
2015-07-23 08:12:36 -04:00
|
|
|
func (s *DockerTrustSuite) TestTrustedIsolatedCreate(c *check.C) {
|
|
|
|
repoName := s.setupTrustedImage(c, "trusted-isolated-create")
|
2015-07-22 12:14:48 -04:00
|
|
|
|
2015-07-23 08:12:36 -04:00
|
|
|
// Try create
|
2017-04-19 08:04:39 -04:00
|
|
|
cli.Docker(cli.Args("--config", "/tmp/docker-isolated-create", "create", repoName), trustedCmd).Assert(c, SuccessTagging)
|
2017-03-28 10:12:41 -04:00
|
|
|
defer os.RemoveAll("/tmp/docker-isolated-create")
|
2015-07-22 12:14:48 -04:00
|
|
|
|
2017-04-19 08:04:39 -04:00
|
|
|
cli.DockerCmd(c, "rmi", repoName)
|
2015-07-22 12:14:48 -04:00
|
|
|
}
|
2015-07-22 19:10:25 -04:00
|
|
|
|
|
|
|
func (s *DockerTrustSuite) TestTrustedCreateFromBadTrustServer(c *check.C) {
|
|
|
|
repoName := fmt.Sprintf("%v/dockerclievilcreate/trusted:latest", privateRegistryURL)
|
2016-02-25 16:40:00 -05:00
|
|
|
evilLocalConfigDir, err := ioutil.TempDir("", "evilcreate-local-config-dir")
|
2015-11-02 23:24:12 -05:00
|
|
|
c.Assert(err, check.IsNil)
|
2015-07-22 19:10:25 -04:00
|
|
|
|
|
|
|
// tag the image and upload it to the private registry
|
2017-04-19 08:04:39 -04:00
|
|
|
cli.DockerCmd(c, "tag", "busybox", repoName)
|
|
|
|
cli.Docker(cli.Args("push", repoName), trustedCmd).Assert(c, SuccessSigningAndPushing)
|
|
|
|
cli.DockerCmd(c, "rmi", repoName)
|
2015-07-22 19:10:25 -04:00
|
|
|
|
|
|
|
// Try create
|
2017-04-19 08:04:39 -04:00
|
|
|
cli.Docker(cli.Args("create", repoName), trustedCmd).Assert(c, SuccessTagging)
|
|
|
|
cli.DockerCmd(c, "rmi", repoName)
|
2015-07-22 19:10:25 -04:00
|
|
|
|
|
|
|
// Kill the notary server, start a new "evil" one.
|
|
|
|
s.not.Close()
|
|
|
|
s.not, err = newTestNotary(c)
|
2015-11-02 23:24:12 -05:00
|
|
|
c.Assert(err, check.IsNil)
|
2015-07-22 19:10:25 -04:00
|
|
|
|
|
|
|
// In order to make an evil server, lets re-init a client (with a different trust dir) and push new data.
|
|
|
|
// tag an image and upload it to the private registry
|
2017-04-19 08:04:39 -04:00
|
|
|
cli.DockerCmd(c, "--config", evilLocalConfigDir, "tag", "busybox", repoName)
|
2015-07-22 19:10:25 -04:00
|
|
|
|
|
|
|
// Push up to the new server
|
2017-04-19 08:04:39 -04:00
|
|
|
cli.Docker(cli.Args("--config", evilLocalConfigDir, "push", repoName), trustedCmd).Assert(c, SuccessSigningAndPushing)
|
2015-07-22 19:10:25 -04:00
|
|
|
|
2016-09-28 15:49:47 -04:00
|
|
|
// Now, try creating with the original client from this new trust server. This should fail because the new root is invalid.
|
2017-04-19 08:04:39 -04:00
|
|
|
cli.Docker(cli.Args("create", repoName), trustedCmd).Assert(c, icmd.Expected{
|
2017-01-05 13:08:24 -05:00
|
|
|
ExitCode: 1,
|
|
|
|
Err: "could not rotate trust to a new trusted root",
|
|
|
|
})
|
2015-07-22 19:10:25 -04:00
|
|
|
}
|
2015-08-18 13:30:44 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestCreateStopSignal(c *check.C) {
|
|
|
|
name := "test_create_stop_signal"
|
|
|
|
dockerCmd(c, "create", "--name", name, "--stop-signal", "9", "busybox")
|
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
res := inspectFieldJSON(c, name, "Config.StopSignal")
|
2015-11-02 23:24:12 -05:00
|
|
|
c.Assert(res, checker.Contains, "9")
|
2015-08-18 13:30:44 -04:00
|
|
|
|
|
|
|
}
|
2016-01-07 23:11:21 -05:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestCreateWithWorkdir(c *check.C) {
|
|
|
|
name := "foo"
|
2016-02-03 09:16:00 -05:00
|
|
|
|
|
|
|
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
2016-02-02 19:00:39 -05:00
|
|
|
dir := prefix + slash + "home" + slash + "foo" + slash + "bar"
|
|
|
|
|
2016-01-07 23:11:21 -05:00
|
|
|
dockerCmd(c, "create", "--name", name, "-w", dir, "busybox")
|
2016-10-07 20:50:42 -04:00
|
|
|
// Windows does not create the workdir until the container is started
|
2017-01-13 11:23:28 -05:00
|
|
|
if testEnv.DaemonPlatform() == "windows" {
|
2016-10-07 20:50:42 -04:00
|
|
|
dockerCmd(c, "start", name)
|
|
|
|
}
|
2016-02-02 19:00:39 -05:00
|
|
|
dockerCmd(c, "cp", fmt.Sprintf("%s:%s", name, dir), prefix+slash+"tmp")
|
2016-01-07 23:11:21 -05:00
|
|
|
}
|
2016-02-27 12:38:26 -05:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestCreateWithInvalidLogOpts(c *check.C) {
|
|
|
|
name := "test-invalidate-log-opts"
|
2016-03-02 07:22:18 -05:00
|
|
|
out, _, err := dockerCmdWithError("create", "--name", name, "--log-opt", "invalid=true", "busybox")
|
2016-02-27 12:38:26 -05:00
|
|
|
c.Assert(err, checker.NotNil)
|
2016-03-02 07:22:18 -05:00
|
|
|
c.Assert(out, checker.Contains, "unknown log opt")
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "-a")
|
2016-02-27 12:38:26 -05:00
|
|
|
c.Assert(out, checker.Not(checker.Contains), name)
|
|
|
|
}
|
2016-03-07 13:56:24 -05:00
|
|
|
|
|
|
|
// #20972
|
|
|
|
func (s *DockerSuite) TestCreate64ByteHexID(c *check.C) {
|
|
|
|
out := inspectField(c, "busybox", "Id")
|
|
|
|
imageID := strings.TrimPrefix(strings.TrimSpace(string(out)), "sha256:")
|
|
|
|
|
|
|
|
dockerCmd(c, "create", imageID)
|
|
|
|
}
|
2016-06-18 17:16:05 -04:00
|
|
|
|
|
|
|
// Test case for #23498
|
|
|
|
func (s *DockerSuite) TestCreateUnsetEntrypoint(c *check.C) {
|
|
|
|
name := "test-entrypoint"
|
|
|
|
dockerfile := `FROM busybox
|
|
|
|
ADD entrypoint.sh /entrypoint.sh
|
|
|
|
RUN chmod 755 /entrypoint.sh
|
|
|
|
ENTRYPOINT ["/entrypoint.sh"]
|
|
|
|
CMD echo foobar`
|
|
|
|
|
2017-04-10 08:42:21 -04:00
|
|
|
ctx := fakecontext.New(c, "",
|
|
|
|
fakecontext.WithDockerfile(dockerfile),
|
|
|
|
fakecontext.WithFiles(map[string]string{
|
|
|
|
"entrypoint.sh": `#!/bin/sh
|
2016-06-18 17:16:05 -04:00
|
|
|
echo "I am an entrypoint"
|
|
|
|
exec "$@"`,
|
2017-04-10 08:42:21 -04:00
|
|
|
}))
|
2016-06-18 17:16:05 -04:00
|
|
|
defer ctx.Close()
|
|
|
|
|
2017-04-10 08:42:21 -04:00
|
|
|
cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx))
|
2016-06-18 17:16:05 -04:00
|
|
|
|
2017-04-10 08:42:21 -04:00
|
|
|
out := cli.DockerCmd(c, "create", "--entrypoint=", name, "echo", "foo").Combined()
|
2016-06-18 17:16:05 -04:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
c.Assert(id, check.Not(check.Equals), "")
|
2017-04-10 08:42:21 -04:00
|
|
|
out = cli.DockerCmd(c, "start", "-a", id).Combined()
|
2016-06-18 17:16:05 -04:00
|
|
|
c.Assert(strings.TrimSpace(out), check.Equals, "foo")
|
|
|
|
}
|
2016-05-26 16:34:48 -04:00
|
|
|
|
|
|
|
// #22471
|
|
|
|
func (s *DockerSuite) TestCreateStopTimeout(c *check.C) {
|
|
|
|
name1 := "test_create_stop_timeout_1"
|
|
|
|
dockerCmd(c, "create", "--name", name1, "--stop-timeout", "15", "busybox")
|
|
|
|
|
|
|
|
res := inspectFieldJSON(c, name1, "Config.StopTimeout")
|
|
|
|
c.Assert(res, checker.Contains, "15")
|
|
|
|
|
|
|
|
name2 := "test_create_stop_timeout_2"
|
|
|
|
dockerCmd(c, "create", "--name", name2, "busybox")
|
|
|
|
|
|
|
|
res = inspectFieldJSON(c, name2, "Config.StopTimeout")
|
|
|
|
c.Assert(res, checker.Contains, "null")
|
|
|
|
}
|