Esempio n. 1
0
func (daemon *Daemon) newContainer(name string, config *runconfig.Config, img *image.Image) (*Container, error) {
	var (
		id  string
		err error
	)
	id, name, err = daemon.generateIdAndName(name)
	if err != nil {
		return nil, err
	}

	daemon.generateHostname(id, config)
	entrypoint, args := daemon.getEntrypointAndArgs(config)

	container := &Container{
		// FIXME: we should generate the ID here instead of receiving it as an argument
		ID:              id,
		Created:         time.Now().UTC(),
		Path:            entrypoint,
		Args:            args, //FIXME: de-duplicate from config
		Config:          config,
		hostConfig:      &runconfig.HostConfig{},
		Image:           img.ID, // Always use the resolved image id
		NetworkSettings: &NetworkSettings{},
		Name:            name,
		Driver:          daemon.driver.String(),
		ExecDriver:      daemon.execDriver.Name(),
	}
	container.root = daemon.containerRoot(container.ID)

	if container.ProcessLabel, container.MountLabel, err = label.GenLabels(""); err != nil {
		return nil, err
	}
	return container, nil
}
Esempio n. 2
0
func (d *driver) generateLXCConfig(c *execdriver.Command) (string, error) {
	var (
		process, mount string
		root           = path.Join(d.root, "containers", c.ID, "config.lxc")
		labels         = c.Config["label"]
	)
	fo, err := os.Create(root)
	if err != nil {
		return "", err
	}
	defer fo.Close()

	if len(labels) > 0 {
		process, mount, err = label.GenLabels(labels[0])
		if err != nil {
			return "", err
		}
	}

	if err := LxcTemplateCompiled.Execute(fo, struct {
		*execdriver.Command
		AppArmor     bool
		ProcessLabel string
		MountLabel   string
	}{
		Command:      c,
		AppArmor:     d.apparmor,
		ProcessLabel: process,
		MountLabel:   mount,
	}); err != nil {
		return "", err
	}
	return root, nil
}