本文整理汇总了Golang中github.com/docker/docker/pkg/integration/cmd.RunCmd函数的典型用法代码示例。如果您正苦于以下问题:Golang RunCmd函数的具体用法?Golang RunCmd怎么用?Golang RunCmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RunCmd函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: dockerCmdInDir
// execute a docker command in a directory
func dockerCmdInDir(c *check.C, path string, args ...string) (string, int, error) {
if err := validateArgs(args...); err != nil {
c.Fatalf(err.Error())
}
result := icmd.RunCmd(icmd.Cmd{Command: binaryWithArgs(args...), Dir: path})
return result.Combined(), result.ExitCode, result.Error
}
示例2: waitForContainer
func waitForContainer(contID string, args ...string) error {
args = append([]string{dockerBinary, "run", "--name", contID}, args...)
result := icmd.RunCmd(icmd.Cmd{Command: args})
if result.Error != nil {
return result.Error
}
return waitRun(contID)
}
示例3: dockerCmdInDirWithTimeout
// execute a docker command in a directory with a timeout
func dockerCmdInDirWithTimeout(timeout time.Duration, path string, args ...string) *icmd.Result {
if err := validateArgs(args...); err != nil {
return &icmd.Result{Error: err}
}
return icmd.RunCmd(icmd.Cmd{
Command: binaryWithArgs(args...),
Timeout: timeout,
Dir: path,
})
}
示例4: BuildImageWithOut
// BuildImageWithOut builds an image with the specified dockerfile and options and returns the output
func (d *Daemon) BuildImageWithOut(name, dockerfile string, useCache bool, buildFlags ...string) (string, int, error) {
buildCmd := BuildImageCmdWithHost(d.dockerBinary, name, dockerfile, d.Sock(), useCache, buildFlags...)
result := icmd.RunCmd(icmd.Cmd{
Command: buildCmd.Args,
Env: buildCmd.Env,
Dir: buildCmd.Dir,
Stdin: buildCmd.Stdin,
Stdout: buildCmd.Stdout,
})
return result.Combined(), result.ExitCode, result.Error
}
示例5: TestAPIDockerAPIVersion
func (s *DockerSuite) TestAPIDockerAPIVersion(c *check.C) {
var svrVersion string
server := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
url := r.URL.Path
svrVersion = url
}))
defer server.Close()
// Test using the env var first
result := icmd.RunCmd(icmd.Cmd{
Command: binaryWithArgs("-H="+server.URL[7:], "version"),
Env: appendBaseEnv(false, "DOCKER_API_VERSION=xxx"),
})
c.Assert(result, icmd.Matches, icmd.Expected{Out: "API version: xxx", ExitCode: 1})
c.Assert(svrVersion, check.Equals, "/vxxx/version", check.Commentf("%s", result.Compare(icmd.Success)))
}
示例6: TestImportWithQuotedChanges
func (s *DockerSuite) TestImportWithQuotedChanges(c *check.C) {
testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
temporaryFile, err := ioutil.TempFile("", "exportImportTest")
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
defer os.Remove(temporaryFile.Name())
result := icmd.RunCmd(icmd.Cmd{
Command: binaryWithArgs("export", "test-import"),
Stdout: bufio.NewWriter(temporaryFile),
})
c.Assert(result, icmd.Matches, icmd.Success)
result = dockerCmdWithResult("import", "-c", `ENTRYPOINT ["/bin/sh", "-c"]`, temporaryFile.Name())
c.Assert(result, icmd.Matches, icmd.Success)
image := strings.TrimSpace(result.Stdout())
result = dockerCmdWithResult("run", "--rm", image, "true")
c.Assert(result, icmd.Matches, icmd.Expected{Out: icmd.None})
}
示例7: TestEventsUntag
func (s *DockerSuite) TestEventsUntag(c *check.C) {
image := "busybox"
dockerCmd(c, "tag", image, "utest:tag1")
dockerCmd(c, "tag", image, "utest:tag2")
dockerCmd(c, "rmi", "utest:tag1")
dockerCmd(c, "rmi", "utest:tag2")
result := icmd.RunCmd(icmd.Cmd{
Command: []string{dockerBinary, "events", "--since=1"},
Timeout: time.Millisecond * 2500,
})
c.Assert(result, icmd.Matches, icmd.Expected{Timeout: true})
events := strings.Split(result.Stdout(), "\n")
nEvents := len(events)
// The last element after the split above will be an empty string, so we
// get the two elements before the last, which are the untags we're
// looking for.
for _, v := range events[nEvents-3 : nEvents-1] {
c.Assert(v, checker.Contains, "untag", check.Commentf("event should be untag"))
}
}
示例8: runCommand
// TODO: update code to call cmd.RunCmd directly, and remove this function
func runCommand(execCmd *exec.Cmd) (exitCode int, err error) {
result := cmd.RunCmd(transformCmd(execCmd))
return result.ExitCode, result.Error
}
示例9: runCommandWithStdoutStderr
// TODO: update code to call cmd.RunCmd directly, and remove this function
func runCommandWithStdoutStderr(execCmd *exec.Cmd) (string, string, int, error) {
result := cmd.RunCmd(transformCmd(execCmd))
return result.Stdout(), result.Stderr(), result.ExitCode, result.Error
}
示例10: runCommandWithOutput
// TODO: update code to call cmd.RunCmd directly, and remove this function
func runCommandWithOutput(execCmd *exec.Cmd) (string, int, error) {
result := cmd.RunCmd(transformCmd(execCmd))
return result.Combined(), result.ExitCode, result.Error
}
示例11: deleteImages
func deleteImages(images ...string) error {
args := []string{dockerBinary, "rmi", "-f"}
return icmd.RunCmd(icmd.Cmd{Command: append(args, images...)}).Error
}