Example #1
0
func (ro *runOptions) Execute(args []string) error {
	capa := &env.Capabilities{}

	config, hostcfg, err := ParseRun(ro, args, capa)
	if err != nil {
		return err
	}

	if config == nil {
		return nil
	}

	if config.Image == "" {
		app.ShowHelp()
		return nil
	}

	tags, err := env.DefaultTagStore()

	if err != nil {
		return err
	}

	container, err := env.ContainerCreate(tags, config)

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

	c := make(chan os.Signal, 1)
	signal.Notify(c, forwardSignals...)

	go func() {
		for {
			sig := <-c
			fmt.Printf("Got signal!\n")
			container.Signal(sig)
			fmt.Printf("Done with signal!\n")
		}
	}()

	err = container.Start(hostcfg)

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

	container.Wait(hostcfg)

	return nil
}
Example #2
0
func (b *buildFile) Start() error {
	b.config.Cmd = []string{"/bin/sh", "-c", "#(nop) START"}

	b.config.Image = b.image

	// Create the container and start it
	container, err := env.ContainerCreate(b.tags, b.config)
	if err != nil {
		return err
	}

	b.container = container

	return nil
}