本文整理汇总了Golang中github.com/docker/docker/runconfig.NewCommand函数的典型用法代码示例。如果您正苦于以下问题:Golang NewCommand函数的具体用法?Golang NewCommand怎么用?Golang NewCommand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewCommand函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: commit
func (b *Builder) commit(id string, autoCmd *runconfig.Command, comment string) error {
if b.disableCommit {
return nil
}
if b.image == "" && !b.noBaseImage {
return fmt.Errorf("Please provide a source image with `from` prior to commit")
}
b.Config.Image = b.image
if id == "" {
cmd := b.Config.Cmd
if runtime.GOOS != "windows" {
b.Config.Cmd = runconfig.NewCommand("/bin/sh", "-c", "#(nop) "+comment)
} else {
b.Config.Cmd = runconfig.NewCommand("cmd", "/S /C", "REM (nop) "+comment)
}
defer func(cmd *runconfig.Command) { b.Config.Cmd = cmd }(cmd)
hit, err := b.probeCache()
if err != nil {
return err
}
if hit {
return nil
}
container, err := b.create()
if err != nil {
return err
}
id = container.ID
if err := container.Mount(); err != nil {
return err
}
defer container.Unmount()
}
container, err := b.Daemon.Get(id)
if err != nil {
return err
}
// Note: Actually copy the struct
autoConfig := *b.Config
autoConfig.Cmd = autoCmd
commitCfg := &daemon.ContainerCommitConfig{
Author: b.maintainer,
Pause: true,
Config: &autoConfig,
}
// Commit the container
image, err := b.Daemon.Commit(container, commitCfg)
if err != nil {
return err
}
b.image = image.ID
return nil
}
开发者ID:bkeyoumarsi,项目名称:docker,代码行数:59,代码来源:internals.go
示例2: BenchmarkRunSequential
func BenchmarkRunSequential(b *testing.B) {
daemon := mkDaemon(b)
defer nuke(daemon)
for i := 0; i < b.N; i++ {
container, _, err := daemon.Create(&runconfig.Config{
Image: GetTestImage(daemon).ID,
Cmd: runconfig.NewCommand("echo", "-n", "foo"),
},
&runconfig.HostConfig{},
"",
)
if err != nil {
b.Fatal(err)
}
defer daemon.Rm(container)
output, err := container.Output()
if err != nil {
b.Fatal(err)
}
if string(output) != "foo" {
b.Fatalf("Unexpected output: %s", output)
}
if err := daemon.Rm(container); err != nil {
b.Fatal(err)
}
}
}
开发者ID:yckrasnodar,项目名称:docker,代码行数:27,代码来源:container_test.go
示例3: TestPostContainersWait
func TestPostContainersWait(t *testing.T) {
eng := NewTestEngine(t)
defer mkDaemonFromEngine(eng, t).Nuke()
containerID := createTestContainer(eng,
&runconfig.Config{
Image: unitTestImageID,
Cmd: runconfig.NewCommand("/bin/sleep", "1"),
OpenStdin: true,
},
t,
)
startContainer(eng, containerID, t)
setTimeout(t, "Wait timed out", 3*time.Second, func() {
r := httptest.NewRecorder()
req, err := http.NewRequest("POST", "/containers/"+containerID+"/wait", bytes.NewReader([]byte{}))
if err != nil {
t.Fatal(err)
}
server.ServeRequest(eng, api.APIVERSION, r, req)
assertHttpNotError(r, t)
var apiWait engine.Env
if err := apiWait.Decode(r.Body); err != nil {
t.Fatal(err)
}
if apiWait.GetInt("StatusCode") != 0 {
t.Fatalf("Non zero exit code for sleep: %d\n", apiWait.GetInt("StatusCode"))
}
})
if containerRunning(eng, containerID, t) {
t.Fatalf("The container should be stopped after wait")
}
}
开发者ID:yckrasnodar,项目名称:docker,代码行数:35,代码来源:api_test.go
示例4: cmd
// CMD foo
//
// Set the default command to run in the container (which may be empty).
// Argument handling is the same as RUN.
//
func cmd(b *builder, args []string, attributes map[string]bool, original string) error {
if err := b.BuilderFlags.Parse(); err != nil {
return err
}
cmdSlice := handleJSONArgs(args, attributes)
if !attributes["json"] {
if runtime.GOOS != "windows" {
cmdSlice = append([]string{"/bin/sh", "-c"}, cmdSlice...)
} else {
cmdSlice = append([]string{"cmd", "/S /C"}, cmdSlice...)
}
}
b.Config.Cmd = runconfig.NewCommand(cmdSlice...)
if err := b.commit("", b.Config.Cmd, fmt.Sprintf("CMD %q", cmdSlice)); err != nil {
return err
}
if len(args) != 0 {
b.cmdSet = true
}
return nil
}
开发者ID:vito,项目名称:garden-linux-release,代码行数:32,代码来源:dispatchers.go
示例5: TestPostContainersCopy
func TestPostContainersCopy(t *testing.T) {
eng := NewTestEngine(t)
defer mkDaemonFromEngine(eng, t).Nuke()
// Create a container and remove a file
containerID := createTestContainer(eng,
&runconfig.Config{
Image: unitTestImageID,
Cmd: runconfig.NewCommand("touch", "/test.txt"),
},
t,
)
containerRun(eng, containerID, t)
r := httptest.NewRecorder()
var copyData engine.Env
copyData.Set("Resource", "/test.txt")
copyData.Set("HostPath", ".")
jsonData := bytes.NewBuffer(nil)
if err := copyData.Encode(jsonData); err != nil {
t.Fatal(err)
}
req, err := http.NewRequest("POST", "/containers/"+containerID+"/copy", jsonData)
if err != nil {
t.Fatal(err)
}
req.Header.Add("Content-Type", "application/json")
server.ServeRequest(eng, api.APIVERSION, r, req)
assertHttpNotError(r, t)
if r.Code != http.StatusOK {
t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code)
}
found := false
for tarReader := tar.NewReader(r.Body); ; {
h, err := tarReader.Next()
if err != nil {
if err == io.EOF {
break
}
t.Fatal(err)
}
if h.Name == "test.txt" {
found = true
break
}
}
if !found {
t.Fatalf("The created test file has not been found in the copied output")
}
}
开发者ID:yckrasnodar,项目名称:docker,代码行数:55,代码来源:api_test.go
示例6: create
func (b *Builder) create() (*daemon.Container, error) {
if b.image == "" && !b.noBaseImage {
return nil, fmt.Errorf("Please provide a source image with `from` prior to run")
}
b.Config.Image = b.image
config := *b.Config
// Create the Pod
podId := fmt.Sprintf("buildpod-%s", utils.RandStr(10, "alpha"))
podString, err := MakeBasicPod(podId, b.image, b.Config.Cmd.Slice())
if err != nil {
return nil, err
}
err = b.Hyperdaemon.CreatePod(podId, podString, false)
if err != nil {
return nil, err
}
// Get the container
var (
containerId = ""
c *daemon.Container
)
ps, ok := b.Hyperdaemon.PodList.GetStatus(podId)
if !ok {
return nil, fmt.Errorf("Cannot find pod %s", podId)
}
for _, i := range ps.Containers {
containerId = i.Id
}
c, err = b.Daemon.Get(containerId)
if err != nil {
glog.Error(err.Error())
return nil, err
}
b.TmpContainers[c.ID] = struct{}{}
b.TmpPods[podId] = struct{}{}
fmt.Fprintf(b.OutStream, " ---> Running in %s\n", stringid.TruncateID(c.ID))
if config.Cmd.Len() > 0 {
// override the entry point that may have been picked up from the base image
s := config.Cmd.Slice()
c.Path = s[0]
c.Args = s[1:]
} else {
config.Cmd = runconfig.NewCommand()
}
return c, nil
}
开发者ID:m1911,项目名称:hyper,代码行数:51,代码来源:internals_darwin.go
示例7: BenchmarkRunParallel
func BenchmarkRunParallel(b *testing.B) {
daemon := mkDaemon(b)
defer nuke(daemon)
var tasks []chan error
for i := 0; i < b.N; i++ {
complete := make(chan error)
tasks = append(tasks, complete)
go func(i int, complete chan error) {
container, _, err := daemon.Create(&runconfig.Config{
Image: GetTestImage(daemon).ID,
Cmd: runconfig.NewCommand("echo", "-n", "foo"),
},
&runconfig.HostConfig{},
"",
)
if err != nil {
complete <- err
return
}
defer daemon.Rm(container)
if err := container.Start(); err != nil {
complete <- err
return
}
if _, err := container.WaitStop(15 * time.Second); err != nil {
complete <- err
return
}
// if string(output) != "foo" {
// complete <- fmt.Errorf("Unexecpted output: %v", string(output))
// }
if err := daemon.Rm(container); err != nil {
complete <- err
return
}
complete <- nil
}(i, complete)
}
var errors []error
for _, task := range tasks {
err := <-task
if err != nil {
errors = append(errors, err)
}
}
if len(errors) > 0 {
b.Fatal(errors)
}
}
开发者ID:yckrasnodar,项目名称:docker,代码行数:51,代码来源:container_test.go
示例8: TestPostContainersStop
func TestPostContainersStop(t *testing.T) {
eng := NewTestEngine(t)
defer mkDaemonFromEngine(eng, t).Nuke()
containerID := createTestContainer(eng,
&runconfig.Config{
Image: unitTestImageID,
Cmd: runconfig.NewCommand("/bin/top"),
OpenStdin: true,
},
t,
)
startContainer(eng, containerID, t)
// Give some time to the process to start
containerWaitTimeout(eng, containerID, t)
if !containerRunning(eng, containerID, t) {
t.Errorf("Container should be running")
}
// Note: as it is a POST request, it requires a body.
req, err := http.NewRequest("POST", "/containers/"+containerID+"/stop?t=1", bytes.NewReader([]byte{}))
if err != nil {
t.Fatal(err)
}
r := httptest.NewRecorder()
server.ServeRequest(eng, api.APIVERSION, r, req)
assertHttpNotError(r, t)
if r.Code != http.StatusNoContent {
t.Fatalf("%d NO CONTENT expected, received %d\n", http.StatusNoContent, r.Code)
}
if containerRunning(eng, containerID, t) {
t.Fatalf("The container hasn't been stopped")
}
req, err = http.NewRequest("POST", "/containers/"+containerID+"/stop?t=1", bytes.NewReader([]byte{}))
if err != nil {
t.Fatal(err)
}
r = httptest.NewRecorder()
server.ServeRequest(eng, api.APIVERSION, r, req)
// Stopping an already stopper container should return a 304
assertHttpNotError(r, t)
if r.Code != http.StatusNotModified {
t.Fatalf("%d NOT MODIFIER expected, received %d\n", http.StatusNotModified, r.Code)
}
}
开发者ID:yckrasnodar,项目名称:docker,代码行数:51,代码来源:api_test.go
示例9: ContainerExecCreate
func (d *Daemon) ContainerExecCreate(job *engine.Job) error {
if len(job.Args) != 1 {
return fmt.Errorf("Usage: %s [options] container command [args]", job.Name)
}
if strings.HasPrefix(d.execDriver.Name(), lxc.DriverName) {
return lxc.ErrExec
}
var name = job.Args[0]
container, err := d.getActiveContainer(name)
if err != nil {
return err
}
config, err := runconfig.ExecConfigFromJob(job)
if err != nil {
return err
}
cmd := runconfig.NewCommand(config.Cmd...)
entrypoint, args := d.getEntrypointAndArgs(runconfig.NewEntrypoint(), cmd)
processConfig := execdriver.ProcessConfig{
Tty: config.Tty,
Entrypoint: entrypoint,
Arguments: args,
User: config.User,
Privileged: config.Privileged,
}
execConfig := &execConfig{
ID: stringid.GenerateRandomID(),
OpenStdin: config.AttachStdin,
OpenStdout: config.AttachStdout,
OpenStderr: config.AttachStderr,
StreamConfig: StreamConfig{},
ProcessConfig: processConfig,
Container: container,
Running: false,
}
container.LogEvent("exec_create: " + execConfig.ProcessConfig.Entrypoint + " " + strings.Join(execConfig.ProcessConfig.Arguments, " "))
d.registerExecCommand(execConfig)
job.Printf("%s\n", execConfig.ID)
return nil
}
开发者ID:yingmsky,项目名称:docker,代码行数:51,代码来源:exec.go
示例10: TestPostContainersStart
func TestPostContainersStart(t *testing.T) {
eng := NewTestEngine(t)
defer mkDaemonFromEngine(eng, t).Nuke()
containerID := createTestContainer(
eng,
&runconfig.Config{
Image: unitTestImageID,
Cmd: runconfig.NewCommand("/bin/cat"),
OpenStdin: true,
},
t,
)
hostConfigJSON, err := json.Marshal(&runconfig.HostConfig{})
req, err := http.NewRequest("POST", "/containers/"+containerID+"/start", bytes.NewReader(hostConfigJSON))
if err != nil {
t.Fatal(err)
}
req.Header.Set("Content-Type", "application/json")
r := httptest.NewRecorder()
server.ServeRequest(eng, api.APIVERSION, r, req)
assertHttpNotError(r, t)
if r.Code != http.StatusNoContent {
t.Fatalf("%d NO CONTENT expected, received %d\n", http.StatusNoContent, r.Code)
}
containerAssertExists(eng, containerID, t)
req, err = http.NewRequest("POST", "/containers/"+containerID+"/start", bytes.NewReader(hostConfigJSON))
if err != nil {
t.Fatal(err)
}
req.Header.Set("Content-Type", "application/json")
r = httptest.NewRecorder()
server.ServeRequest(eng, api.APIVERSION, r, req)
// Starting an already started container should return a 304
assertHttpNotError(r, t)
if r.Code != http.StatusNotModified {
t.Fatalf("%d NOT MODIFIER expected, received %d\n", http.StatusNotModified, r.Code)
}
containerAssertExists(eng, containerID, t)
containerKill(eng, containerID, t)
}
开发者ID:yckrasnodar,项目名称:docker,代码行数:50,代码来源:api_test.go
示例11: commit
func (b *Builder) commit(id string, autoCmd *runconfig.Command, comment string) error {
if b.disableCommit {
return nil
}
if b.image == "" && !b.noBaseImage {
return fmt.Errorf("Please provide a source image with `from` prior to commit")
}
b.Config.Image = b.image
if id == "" {
cmd := b.Config.Cmd
b.Config.Cmd = runconfig.NewCommand("/bin/sh", "-c", "#(nop) "+comment)
defer func(cmd *runconfig.Command) { b.Config.Cmd = cmd }(cmd)
hit, err := b.probeCache()
if err != nil {
return err
}
if hit {
return nil
}
container, err := b.create()
if err != nil {
return err
}
id = container.ID
if err := container.Mount(); err != nil {
return err
}
defer container.Unmount()
}
container, err := b.Daemon.Get(id)
if err != nil {
return err
}
// Note: Actually copy the struct
autoConfig := *b.Config
autoConfig.Cmd = autoCmd
// Commit the container
image, err := b.Daemon.Commit(container, "", "", "", b.maintainer, true, &autoConfig)
if err != nil {
return err
}
b.image = image.ID
return nil
}
开发者ID:justone,项目名称:docker,代码行数:49,代码来源:internals.go
示例12: ContainerExecCreate
func (d *Daemon) ContainerExecCreate(config *runconfig.ExecConfig) (string, error) {
// Not all drivers support Exec (LXC for example)
if err := checkExecSupport(d.execDriver.Name()); err != nil {
return "", err
}
container, err := d.getActiveContainer(config.Container)
if err != nil {
return "", err
}
cmd := runconfig.NewCommand(config.Cmd...)
entrypoint, args := d.getEntrypointAndArgs(runconfig.NewEntrypoint(), cmd)
user := config.User
if len(user) == 0 {
user = container.Config.User
}
processConfig := &execdriver.ProcessConfig{
Tty: config.Tty,
Entrypoint: entrypoint,
Arguments: args,
User: user,
Privileged: config.Privileged,
}
execConfig := &execConfig{
ID: stringid.GenerateNonCryptoID(),
OpenStdin: config.AttachStdin,
OpenStdout: config.AttachStdout,
OpenStderr: config.AttachStderr,
StreamConfig: StreamConfig{},
ProcessConfig: processConfig,
Container: container,
Running: false,
waitStart: make(chan struct{}),
}
d.registerExecCommand(execConfig)
container.LogEvent("exec_create: " + execConfig.ProcessConfig.Entrypoint + " " + strings.Join(execConfig.ProcessConfig.Arguments, " "))
return execConfig.ID, nil
}
开发者ID:ch3lo,项目名称:docker,代码行数:46,代码来源:exec.go
示例13: cmd
// CMD foo
//
// Set the default command to run in the container (which may be empty).
// Argument handling is the same as RUN.
//
func cmd(b *Builder, args []string, attributes map[string]bool, original string) error {
cmdSlice := handleJsonArgs(args, attributes)
if !attributes["json"] {
cmdSlice = append([]string{"/bin/sh", "-c"}, cmdSlice...)
}
b.Config.Cmd = runconfig.NewCommand(cmdSlice...)
if err := b.commit("", b.Config.Cmd, fmt.Sprintf("CMD %q", cmdSlice)); err != nil {
return err
}
if len(args) != 0 {
b.cmdSet = true
}
return nil
}
开发者ID:yingmsky,项目名称:docker,代码行数:24,代码来源:dispatchers.go
示例14: create
func (b *Builder) create() (*daemon.Container, error) {
if b.image == "" && !b.noBaseImage {
return nil, fmt.Errorf("Please provide a source image with `from` prior to run")
}
b.Config.Image = b.image
hostConfig := &runconfig.HostConfig{
CpuShares: b.cpuShares,
CpuPeriod: b.cpuPeriod,
CpuQuota: b.cpuQuota,
CpusetCpus: b.cpuSetCpus,
CpusetMems: b.cpuSetMems,
CgroupParent: b.cgroupParent,
Memory: b.memory,
MemorySwap: b.memorySwap,
NetworkMode: "bridge",
}
config := *b.Config
// Create the container
c, warnings, err := b.Daemon.Create(b.Config, hostConfig, "")
if err != nil {
return nil, err
}
for _, warning := range warnings {
fmt.Fprintf(b.OutStream, " ---> [Warning] %s\n", warning)
}
b.TmpContainers[c.ID] = struct{}{}
fmt.Fprintf(b.OutStream, " ---> Running in %s\n", stringid.TruncateID(c.ID))
if config.Cmd.Len() > 0 {
// override the entry point that may have been picked up from the base image
s := config.Cmd.Slice()
c.Path = s[0]
c.Args = s[1:]
} else {
config.Cmd = runconfig.NewCommand()
}
return c, nil
}
开发者ID:justone,项目名称:docker,代码行数:43,代码来源:internals.go
示例15: TestPostContainersRestart
func TestPostContainersRestart(t *testing.T) {
eng := NewTestEngine(t)
defer mkDaemonFromEngine(eng, t).Nuke()
containerID := createTestContainer(eng,
&runconfig.Config{
Image: unitTestImageID,
Cmd: runconfig.NewCommand("/bin/top"),
OpenStdin: true,
},
t,
)
startContainer(eng, containerID, t)
// Give some time to the process to start
containerWaitTimeout(eng, containerID, t)
if !containerRunning(eng, containerID, t) {
t.Errorf("Container should be running")
}
req, err := http.NewRequest("POST", "/containers/"+containerID+"/restart?t=1", bytes.NewReader([]byte{}))
if err != nil {
t.Fatal(err)
}
r := httptest.NewRecorder()
server.ServeRequest(eng, api.APIVERSION, r, req)
assertHttpNotError(r, t)
if r.Code != http.StatusNoContent {
t.Fatalf("%d NO CONTENT expected, received %d\n", http.StatusNoContent, r.Code)
}
// Give some time to the process to restart
containerWaitTimeout(eng, containerID, t)
if !containerRunning(eng, containerID, t) {
t.Fatalf("Container should be running")
}
containerKill(eng, containerID, t)
}
开发者ID:yckrasnodar,项目名称:docker,代码行数:42,代码来源:api_test.go
示例16: TestDestroyWithInitLayer
func TestDestroyWithInitLayer(t *testing.T) {
daemon := mkDaemon(t)
defer nuke(daemon)
container, _, err := daemon.Create(&runconfig.Config{
Image: GetTestImage(daemon).ID,
Cmd: runconfig.NewCommand("ls", "-al"),
},
&runconfig.HostConfig{},
"")
if err != nil {
t.Fatal(err)
}
// Destroy
if err := daemon.Rm(container); err != nil {
t.Fatal(err)
}
// Make sure daemon.Exists() behaves correctly
if daemon.Exists("test_destroy") {
t.Fatalf("Exists() returned true")
}
// Make sure daemon.List() doesn't list the destroyed container
if len(daemon.List()) != 0 {
t.Fatalf("Expected 0 container, %v found", len(daemon.List()))
}
driver := daemon.Graph().Driver()
// Make sure that the container does not exist in the driver
if _, err := driver.Get(container.ID, ""); err == nil {
t.Fatal("Conttainer should not exist in the driver")
}
// Make sure that the init layer is removed from the driver
if _, err := driver.Get(fmt.Sprintf("%s-init", container.ID), ""); err == nil {
t.Fatal("Container's init layer should not exist in the driver")
}
}
开发者ID:yckrasnodar,项目名称:docker,代码行数:41,代码来源:runtime_test.go
示例17: ContainerExecCreate
func (d *Daemon) ContainerExecCreate(config *runconfig.ExecConfig) (string, error) {
if strings.HasPrefix(d.execDriver.Name(), lxc.DriverName) {
return "", lxc.ErrExec
}
container, err := d.getActiveContainer(config.Container)
if err != nil {
return "", err
}
cmd := runconfig.NewCommand(config.Cmd...)
entrypoint, args := d.getEntrypointAndArgs(runconfig.NewEntrypoint(), cmd)
processConfig := execdriver.ProcessConfig{
Tty: config.Tty,
Entrypoint: entrypoint,
Arguments: args,
User: config.User,
Privileged: config.Privileged,
}
execConfig := &execConfig{
ID: stringid.GenerateRandomID(),
OpenStdin: config.AttachStdin,
OpenStdout: config.AttachStdout,
OpenStderr: config.AttachStderr,
StreamConfig: StreamConfig{},
ProcessConfig: processConfig,
Container: container,
Running: false,
}
container.LogEvent("exec_create: " + execConfig.ProcessConfig.Entrypoint + " " + strings.Join(execConfig.ProcessConfig.Arguments, " "))
d.registerExecCommand(execConfig)
return execConfig.ID, nil
}
开发者ID:pbx0,项目名称:docker,代码行数:40,代码来源:exec.go
示例18: TestStdin
func TestStdin(t *testing.T) {
daemon := mkDaemon(t)
defer nuke(daemon)
container, _, err := daemon.Create(&runconfig.Config{
Image: GetTestImage(daemon).ID,
Cmd: runconfig.NewCommand("cat"),
OpenStdin: true,
},
&runconfig.HostConfig{},
"",
)
if err != nil {
t.Fatal(err)
}
defer daemon.Rm(container)
stdin := container.StdinPipe()
stdout := container.StdoutPipe()
if err := container.Start(); err != nil {
t.Fatal(err)
}
defer stdin.Close()
defer stdout.Close()
if _, err := io.WriteString(stdin, "hello world"); err != nil {
t.Fatal(err)
}
if err := stdin.Close(); err != nil {
t.Fatal(err)
}
container.WaitStop(-1 * time.Second)
output, err := ioutil.ReadAll(stdout)
if err != nil {
t.Fatal(err)
}
if string(output) != "hello world" {
t.Fatalf("Unexpected output. Expected %s, received: %s", "hello world", string(output))
}
}
开发者ID:yckrasnodar,项目名称:docker,代码行数:39,代码来源:container_test.go
示例19: TestDestroy
func TestDestroy(t *testing.T) {
daemon := mkDaemon(t)
defer nuke(daemon)
container, _, err := daemon.Create(&runconfig.Config{
Image: GetTestImage(daemon).ID,
Cmd: runconfig.NewCommand("ls", "-al"),
},
&runconfig.HostConfig{},
"")
if err != nil {
t.Fatal(err)
}
// Destroy
if err := daemon.Rm(container); err != nil {
t.Error(err)
}
// Make sure daemon.Exists() behaves correctly
if daemon.Exists("test_destroy") {
t.Errorf("Exists() returned true")
}
// Make sure daemon.List() doesn't list the destroyed container
if len(daemon.List()) != 0 {
t.Errorf("Expected 0 container, %v found", len(daemon.List()))
}
// Make sure daemon.Get() refuses to return the unexisting container
if c, _ := daemon.Get(container.ID); c != nil {
t.Errorf("Got a container that should not exist")
}
// Test double destroy
if err := daemon.Rm(container); err == nil {
// It should have failed
t.Errorf("Double destroy did not fail")
}
}
开发者ID:yckrasnodar,项目名称:docker,代码行数:39,代码来源:runtime_test.go
示例20: TestDaemonCreate
func TestDaemonCreate(t *testing.T) {
daemon := mkDaemon(t)
defer nuke(daemon)
// Make sure we start we 0 containers
if len(daemon.List()) != 0 {
t.Errorf("Expected 0 containers, %v found", len(daemon.List()))
}
container, _, err := daemon.Create(&runconfig.Config{
Image: GetTestImage(daemon).ID,
Cmd: runconfig.NewCommand("ls", "-al"),
},
&runconfig.HostConfig{},
"",
)
if err != nil {
t.Fatal(err)
}
defer func() {
if err := daemon.Rm(container); err != nil {
t.Error(err)
}
}()
// Make sure we can find the newly created container with List()
if len(daemon.List()) != 1 {
t.Errorf("Expected 1 container, %v found", len(daemon.List()))
}
// Make sure the container List() returns is the right one
if daemon.List()[0].ID != container.ID {
t.Errorf("Unexpected container %v returned by List", daemon.List()[0])
}
// Make sure we can get the container with Get()
if _, err := daemon.Get(container.ID); err != nil {
t.Errorf("Unable to get newly created container")
}
// Make sure it is the right container
if c, _ := daemon.Get(container.ID); c != container {
t.Errorf("Get() returned the wrong container")
}
// Make sure Exists returns it as existing
if !daemon.Exists(container.ID) {
t.Errorf("Exists() returned false for a newly created container")
}
// Test that conflict error displays correct details
cmd := runconfig.NewCommand("ls", "-al")
testContainer, _, _ := daemon.Create(
&runconfig.Config{
Image: GetTestImage(daemon).ID,
Cmd: cmd,
},
&runconfig.HostConfig{},
"conflictname",
)
if _, _, err := daemon.Create(&runconfig.Config{Image: GetTestImage(daemon).ID, Cmd: cmd}, &runconfig.HostConfig{}, testContainer.Name); err == nil || !strings.Contains(err.Error(), stringid.TruncateID(testContainer.ID)) {
t.Fatalf("Name conflict error doesn't include the correct short id. Message was: %v", err)
}
// Make sure create with bad parameters returns an error
if _, _, err = daemon.Create(&runconfig.Config{Image: GetTestImage(daemon).ID}, &runconfig.HostConfig{}, ""); err == nil {
t.Fatal("Builder.Create should throw an error when Cmd is missing")
}
if _, _, err := daemon.Create(
&runconfig.Config{
Image: GetTestImage(daemon).ID,
Cmd: runconfig.NewCommand(),
},
&runconfig.HostConfig{},
"",
); err == nil {
t.Fatal("Builder.Create should throw an error when Cmd is empty")
}
config := &runconfig.Config{
Image: GetTestImage(daemon).ID,
Cmd: runconfig.NewCommand("/bin/ls"),
PortSpecs: []string{"80"},
}
container, _, err = daemon.Create(config, &runconfig.HostConfig{}, "")
_, err = daemon.Commit(container, "testrepo", "testtag", "", "", true, config)
if err != nil {
t.Error(err)
}
// test expose 80:8000
container, warnings, err := daemon.Create(&runconfig.Config{
Image: GetTestImage(daemon).ID,
Cmd: runconfig.NewCommand("ls", "-al"),
PortSpecs: []string{"80:8000"},
},
&runconfig.HostConfig{},
//.........这里部分代码省略.........
开发者ID:yckrasnodar,项目名称:docker,代码行数:101,代码来源:runtime_test.go
注:本文中的github.com/docker/docker/runconfig.NewCommand函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论