Esempio n. 1
0
func (co *commitOptions) Execute(args []string) error {
	if err := app.CheckArity(1, 1, args); err != nil {
		return err
	}

	id := utils.ExpandID(env.DIR, args[0])

	cont, err := env.LoadContainer(env.DIR, id)

	if err != nil {
		return fmt.Errorf("Unable to load %s: %s\n", id, err)
	}

	ts, err := env.DefaultTagStore()

	if err != nil {
		return err
	}

	img, err := cont.Commit(co.Comment, co.Author, nil, co.Squash, false)

	if err != nil {
		return fmt.Errorf("Unable to create image: %s\n", err)
	}

	repo, tag := env.ParseRepositoryTag(args[1])

	ts.Add(repo, tag, img.ID)
	ts.Flush()

	return nil
}
Esempio n. 2
0
func (po *psOptions) Execute(args []string) error {
	if err := app.CheckArity(0, 0, args); err != nil {
		return err
	}

	dir, err := ioutil.ReadDir(path.Join(env.DIR, "containers"))

	if err != nil {
		return err
	}

	ts, err := env.DefaultTagStore()

	w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
	fmt.Fprintf(w, "  ID\tREPO\tCREATED\n")

	var cs Containers

	for _, f := range dir {
		id := f.Name()

		cont, err := env.LoadContainer(env.DIR, id)
		if err != nil {
			continue
		}

		cs = append(cs, cont)
	}

	sort.Sort(cs)

	for _, cont := range cs {
		repo, tag := ts.Find(cont.Image)

		state := "  "

		_, err := os.Stat(cont.PathTo("running"))

		if err == nil {
			state = "* "
		}

		if repo == "" {
			fmt.Fprintf(w, "%s%s\t \t%s\n", state, cont.ID[0:12], cont.Created.String())
		} else {
			fmt.Fprintf(w, "%s%s\t%s:%s\t%s\n", state, cont.ID[0:12], repo, tag, cont.Created.String())
		}

	}

	w.Flush()

	return nil
}
Esempio n. 3
0
func (po *portOptions) Execute(args []string) error {
	if err := app.CheckArity(1, 1, args); err != nil {
		return err
	}

	id := utils.ExpandID(env.DIR, args[0])

	cont, err := env.LoadContainer(env.DIR, id)

	if err != nil {
		return fmt.Errorf("Error loading conatiner %s: %s\n", id, err)
	}

	if po.TCP != "" {
		h, ok := cont.NetworkSettings.PortMapping["Tcp"][po.TCP]

		if ok {
			fmt.Printf("%s\n", h)
		} else {
			return fmt.Errorf("Unknown tcp port %s\n", po.TCP)
		}

		return nil
	}

	if po.UDP != "" {
		h, ok := cont.NetworkSettings.PortMapping["Udp"][po.UDP]

		if ok {
			fmt.Printf("%s\n", h)
		} else {
			return fmt.Errorf("Unknown udp port %s\n", po.UDP)
		}

		return nil
	}

	for c, h := range cont.NetworkSettings.PortMapping["Tcp"] {
		fmt.Printf("tcp %s -> tcp %s\n", c, h)
	}

	for c, h := range cont.NetworkSettings.PortMapping["Udp"] {
		fmt.Printf("udp %s -> udp %s\n", c, h)
	}

	return nil
}
Esempio n. 4
0
func (io *inspectOptions) Execute(args []string) error {
	if err := app.CheckArity(1, 1, args); err != nil {
		return err
	}

	id := utils.ExpandID(env.DIR, args[0])

	cont, err := env.LoadContainer(env.DIR, id)

	if err != nil {
		return err
	}

	data, err := json.Marshal(cont)

	var out bytes.Buffer

	json.Indent(&out, data, "", "  ")

	out.WriteTo(os.Stdout)
	os.Stdout.Write([]byte("\n"))

	return nil
}