mirror of https://github.com/docker/docs.git
Add initial plugin flag to pass lxc and native driver options
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
56c156190a
commit
f7b3e879fc
|
@ -13,6 +13,7 @@ type HostConfig struct {
|
||||||
PortBindings nat.PortMap
|
PortBindings nat.PortMap
|
||||||
Links []string
|
Links []string
|
||||||
PublishAllPorts bool
|
PublishAllPorts bool
|
||||||
|
PluginOptions map[string][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type KeyValuePair struct {
|
type KeyValuePair struct {
|
||||||
|
@ -28,6 +29,7 @@ func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
|
||||||
}
|
}
|
||||||
job.GetenvJson("LxcConf", &hostConfig.LxcConf)
|
job.GetenvJson("LxcConf", &hostConfig.LxcConf)
|
||||||
job.GetenvJson("PortBindings", &hostConfig.PortBindings)
|
job.GetenvJson("PortBindings", &hostConfig.PortBindings)
|
||||||
|
job.GetenvJson("PluginOptions", &hostConfig.PluginOptions)
|
||||||
if Binds := job.GetenvList("Binds"); Binds != nil {
|
if Binds := job.GetenvList("Binds"); Binds != nil {
|
||||||
hostConfig.Binds = Binds
|
hostConfig.Binds = Binds
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
|
||||||
flDnsSearch = opts.NewListOpts(opts.ValidateDomain)
|
flDnsSearch = opts.NewListOpts(opts.ValidateDomain)
|
||||||
flVolumesFrom opts.ListOpts
|
flVolumesFrom opts.ListOpts
|
||||||
flLxcOpts opts.ListOpts
|
flLxcOpts opts.ListOpts
|
||||||
|
flPluginOpts opts.ListOpts
|
||||||
|
|
||||||
flAutoRemove = cmd.Bool([]string{"#rm", "-rm"}, false, "Automatically remove the container when it exits (incompatible with -d)")
|
flAutoRemove = cmd.Bool([]string{"#rm", "-rm"}, false, "Automatically remove the container when it exits (incompatible with -d)")
|
||||||
flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: Run container in the background, print new container id")
|
flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: Run container in the background, print new container id")
|
||||||
|
@ -77,6 +78,7 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
|
||||||
cmd.Var(&flDnsSearch, []string{"-dns-search"}, "Set custom dns search domains")
|
cmd.Var(&flDnsSearch, []string{"-dns-search"}, "Set custom dns search domains")
|
||||||
cmd.Var(&flVolumesFrom, []string{"#volumes-from", "-volumes-from"}, "Mount volumes from the specified container(s)")
|
cmd.Var(&flVolumesFrom, []string{"#volumes-from", "-volumes-from"}, "Mount volumes from the specified container(s)")
|
||||||
cmd.Var(&flLxcOpts, []string{"#lxc-conf", "-lxc-conf"}, "Add custom lxc options --lxc-conf=\"lxc.cgroup.cpuset.cpus = 0,1\"")
|
cmd.Var(&flLxcOpts, []string{"#lxc-conf", "-lxc-conf"}, "Add custom lxc options --lxc-conf=\"lxc.cgroup.cpuset.cpus = 0,1\"")
|
||||||
|
cmd.Var(&flPluginOpts, []string{"-plugin"}, "Add custom plugin options")
|
||||||
|
|
||||||
if err := cmd.Parse(args); err != nil {
|
if err := cmd.Parse(args); err != nil {
|
||||||
return nil, nil, cmd, err
|
return nil, nil, cmd, err
|
||||||
|
@ -206,6 +208,8 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
|
||||||
WorkingDir: *flWorkingDir,
|
WorkingDir: *flWorkingDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pluginOptions := parsePluginOpts(flPluginOpts)
|
||||||
|
|
||||||
hostConfig := &HostConfig{
|
hostConfig := &HostConfig{
|
||||||
Binds: binds,
|
Binds: binds,
|
||||||
ContainerIDFile: *flContainerIDFile,
|
ContainerIDFile: *flContainerIDFile,
|
||||||
|
@ -214,6 +218,7 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
|
||||||
PortBindings: portBindings,
|
PortBindings: portBindings,
|
||||||
Links: flLinks.GetAll(),
|
Links: flLinks.GetAll(),
|
||||||
PublishAllPorts: *flPublishAll,
|
PublishAllPorts: *flPublishAll,
|
||||||
|
PluginOptions: pluginOptions,
|
||||||
}
|
}
|
||||||
|
|
||||||
if sysInfo != nil && flMemory > 0 && !sysInfo.SwapLimit {
|
if sysInfo != nil && flMemory > 0 && !sysInfo.SwapLimit {
|
||||||
|
@ -247,3 +252,16 @@ func parseLxcOpt(opt string) (string, string, error) {
|
||||||
}
|
}
|
||||||
return strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]), nil
|
return strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parsePluginOpts(opts opts.ListOpts) map[string][]string {
|
||||||
|
out := make(map[string][]string, len(opts.GetAll()))
|
||||||
|
for _, o := range opts.GetAll() {
|
||||||
|
parts := strings.SplitN(o, " ", 2)
|
||||||
|
values, exists := out[parts[0]]
|
||||||
|
if !exists {
|
||||||
|
values = []string{}
|
||||||
|
}
|
||||||
|
out[parts[0]] = append(values, parts[1])
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
|
@ -361,7 +361,7 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s
|
||||||
func populateCommand(c *Container) {
|
func populateCommand(c *Container) {
|
||||||
var (
|
var (
|
||||||
en *execdriver.Network
|
en *execdriver.Network
|
||||||
driverConfig []string
|
driverConfig = c.hostConfig.PluginOptions
|
||||||
)
|
)
|
||||||
|
|
||||||
en = &execdriver.Network{
|
en = &execdriver.Network{
|
||||||
|
@ -379,11 +379,15 @@ func populateCommand(c *Container) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// merge in the lxc conf options into the generic config map
|
||||||
if lxcConf := c.hostConfig.LxcConf; lxcConf != nil {
|
if lxcConf := c.hostConfig.LxcConf; lxcConf != nil {
|
||||||
|
lxc := driverConfig["lxc"]
|
||||||
for _, pair := range lxcConf {
|
for _, pair := range lxcConf {
|
||||||
driverConfig = append(driverConfig, fmt.Sprintf("%s = %s", pair.Key, pair.Value))
|
lxc = append(lxc, fmt.Sprintf("%s = %s", pair.Key, pair.Value))
|
||||||
}
|
}
|
||||||
|
driverConfig["lxc"] = lxc
|
||||||
}
|
}
|
||||||
|
|
||||||
resources := &execdriver.Resources{
|
resources := &execdriver.Resources{
|
||||||
Memory: c.Config.Memory,
|
Memory: c.Config.Memory,
|
||||||
MemorySwap: c.Config.MemorySwap,
|
MemorySwap: c.Config.MemorySwap,
|
||||||
|
|
|
@ -112,20 +112,20 @@ type Mount struct {
|
||||||
type Command struct {
|
type Command struct {
|
||||||
exec.Cmd `json:"-"`
|
exec.Cmd `json:"-"`
|
||||||
|
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Privileged bool `json:"privileged"`
|
Privileged bool `json:"privileged"`
|
||||||
User string `json:"user"`
|
User string `json:"user"`
|
||||||
Rootfs string `json:"rootfs"` // root fs of the container
|
Rootfs string `json:"rootfs"` // root fs of the container
|
||||||
InitPath string `json:"initpath"` // dockerinit
|
InitPath string `json:"initpath"` // dockerinit
|
||||||
Entrypoint string `json:"entrypoint"`
|
Entrypoint string `json:"entrypoint"`
|
||||||
Arguments []string `json:"arguments"`
|
Arguments []string `json:"arguments"`
|
||||||
WorkingDir string `json:"working_dir"`
|
WorkingDir string `json:"working_dir"`
|
||||||
ConfigPath string `json:"config_path"` // this should be able to be removed when the lxc template is moved into the driver
|
ConfigPath string `json:"config_path"` // this should be able to be removed when the lxc template is moved into the driver
|
||||||
Tty bool `json:"tty"`
|
Tty bool `json:"tty"`
|
||||||
Network *Network `json:"network"`
|
Network *Network `json:"network"`
|
||||||
Config []string `json:"config"` // generic values that specific drivers can consume
|
Config map[string][]string `json:"config"` // generic values that specific drivers can consume
|
||||||
Resources *Resources `json:"resources"`
|
Resources *Resources `json:"resources"`
|
||||||
Mounts []Mount `json:"mounts"`
|
Mounts []Mount `json:"mounts"`
|
||||||
|
|
||||||
Terminal Terminal `json:"-"` // standard or tty terminal
|
Terminal Terminal `json:"-"` // standard or tty terminal
|
||||||
Console string `json:"-"` // dev/console path
|
Console string `json:"-"` // dev/console path
|
||||||
|
|
|
@ -118,8 +118,8 @@ lxc.cgroup.cpu.shares = {{.Resources.CpuShares}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{if .Config}}
|
{{if .Config.lxc}}
|
||||||
{{range $value := .Config}}
|
{{range $value := .Config.lxc}}
|
||||||
{{$value}}
|
{{$value}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
@ -75,10 +75,11 @@ func TestCustomLxcConfig(t *testing.T) {
|
||||||
command := &execdriver.Command{
|
command := &execdriver.Command{
|
||||||
ID: "1",
|
ID: "1",
|
||||||
Privileged: false,
|
Privileged: false,
|
||||||
Config: []string{
|
Config: map[string][]string{"lxc": {
|
||||||
"lxc.utsname = docker",
|
"lxc.utsname = docker",
|
||||||
"lxc.cgroup.cpuset.cpus = 0,1",
|
"lxc.cgroup.cpuset.cpus = 0,1",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
Network: &execdriver.Network{
|
Network: &execdriver.Network{
|
||||||
Mtu: 1500,
|
Mtu: 1500,
|
||||||
Interface: nil,
|
Interface: nil,
|
||||||
|
|
|
@ -184,10 +184,8 @@ func (d *driver) removeContainerRoot(id string) error {
|
||||||
func (d *driver) validateCommand(c *execdriver.Command) error {
|
func (d *driver) validateCommand(c *execdriver.Command) error {
|
||||||
// we need to check the Config of the command to make sure that we
|
// we need to check the Config of the command to make sure that we
|
||||||
// do not have any of the lxc-conf variables
|
// do not have any of the lxc-conf variables
|
||||||
for _, conf := range c.Config {
|
for _, conf := range c.Config["native"] {
|
||||||
if strings.Contains(conf, "lxc") {
|
log.Println(conf)
|
||||||
return fmt.Errorf("%s is not supported by the native driver", conf)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue