示例#1
0
func (i *Image) Remove() error {
	exitCode := cmd.ExitCode("docker", "rmi", fmt.Sprintf("%s:%s", i.Name, i.Tag))
	if exitCode == 0 {
		return nil
	}
	return fmt.Errorf("exit code %d", exitCode)
}
示例#2
0
func RequireDaemon() {
	if c := cmd.ExitCode("docker", "ps"); c != 0 {
		cli.Logf("`docker ps` exited with code %d", c)
		if dockermachine.Installed() {
			vms := dockermachine.RunningVMs()
			if len(vms) != 0 {
				cli.Fatalf(`Tip: eval "$(docker-machine env %s)"`, vms[0])
			}
			vms = dockermachine.VMs()
			switch len(vms) {
			case 0:
				cli.Logf("Tip: you should create a machine using docker-machine")
			case 1:
				start := ""
				if cmd.Stdout("docker-machine", "status", vms[0]) != "Running" {
					start = fmt.Sprintf("docker-machine start %s && ", vms[0])
				}
				cli.Logf(`Tip: %seval "$(docker-machine env %s)"`, start, vms[0])
			default:
				cli.Logf("Tip: start one of your docker machines (%s)",
					strings.Join(vms, ", "))
			}
		}
		cli.Fatal()
	}
}
示例#3
0
文件: git.go 项目: liamjbennett/sous
func IndexIsDirty() bool {
	code := cmd.ExitCode("git", "diff-index", "--quiet", "HEAD")
	if code > 1 || code < 0 {
		cli.Fatalf("Unable to determine if git index is dirty; Got exit code %d; want 0-1")
	}
	return code == 1
}
示例#4
0
文件: git.go 项目: liamjbennett/sous
func RequireVersion(r *version.R) {
	if c := cmd.ExitCode("git", "--version"); c != 0 {
		cli.Fatalf("git required")
	}
	v := version.Version(cmd.Table("git", "--version")[0][2])
	if !r.IsSatisfiedBy(v) {
		cli.Fatalf("you have git version %s; want %s", v, r.Original)
	}
}
示例#5
0
func (c *container) Inspect() (*DockerContainer, bool) {
	if cmd.ExitCode("docker", "inspect", c.effectiveName()) != 0 {
		return nil, false
	}
	var dc []*DockerContainer
	cmd.JSON(&dc, "docker", "inspect", c.effectiveName())
	if len(dc) == 0 {
		return nil, false
	}
	if len(dc) != 1 {
		cli.Fatalf("Docker inspect %s returned more than one result, please open a GitHub issue about this",
			c.effectiveName())
	}
	// The seond return value checks that the thing we inspected was, in fact, the
	// relevant container, since docker inpect takes both container and image
	// names and IDs, so it's a bit ambiguous otherwise.
	cont := dc[0]
	return cont, cont.Name == "/"+c.Name() || cont.ID == c.CID()
}
示例#6
0
func (c *container) Wait() error {
	if ex := cmd.ExitCode("docker", "wait", c.effectiveName()); ex != 0 {
		return fmt.Errorf("Unable to wait on docker container %s", c)
	}
	return nil
}
示例#7
0
func (c *container) Start() error {
	if ex := cmd.ExitCode("docker", "start", c.effectiveName()); ex != 0 {
		return fmt.Errorf("Unable to start docker container %s", c)
	}
	return nil
}
示例#8
0
func (c *container) ForceRemove() error {
	if ex := cmd.ExitCode("docker", "rm", "-f", c.effectiveName()); ex != 0 {
		return fmt.Errorf("Unable to remove docker container %s", c)
	}
	return nil
}
示例#9
0
func (c *container) Kill() error {
	if ex := cmd.ExitCode("docker", "kill", c.effectiveName()); ex != 0 {
		return fmt.Errorf("Unable to kill docker container %s", c)
	}
	return nil
}
示例#10
0
func Commit(cid, tag string) error {
	if code := cmd.ExitCode("docker", "commit", cid, tag); code != 0 {
		return fmt.Errorf("Command failed with exit code %d", code)
	}
	return nil
}
示例#11
0
func Installed() bool {
	return cmd.ExitCode("docker-machine") == 0
}