|
@@ -90,6 +90,7 @@ type HostConfig struct {
|
|
Binds []string
|
|
Binds []string
|
|
ContainerIDFile string
|
|
ContainerIDFile string
|
|
LxcConf []KeyValuePair
|
|
LxcConf []KeyValuePair
|
|
|
|
+ AutoRemove bool
|
|
}
|
|
}
|
|
|
|
|
|
type BindMap struct {
|
|
type BindMap struct {
|
|
@@ -126,6 +127,7 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig,
|
|
flContainerIDFile := cmd.String("cidfile", "", "Write the container ID to the file")
|
|
flContainerIDFile := cmd.String("cidfile", "", "Write the container ID to the file")
|
|
flNetwork := cmd.Bool("n", true, "Enable networking for this container")
|
|
flNetwork := cmd.Bool("n", true, "Enable networking for this container")
|
|
flPrivileged := cmd.Bool("privileged", false, "Give extended privileges to this container")
|
|
flPrivileged := cmd.Bool("privileged", false, "Give extended privileges to this container")
|
|
|
|
+ flAutoRemove := cmd.Bool("rm", false, "Automatically remove the container when it exits (incompatible with -d)")
|
|
|
|
|
|
if capabilities != nil && *flMemory > 0 && !capabilities.MemoryLimit {
|
|
if capabilities != nil && *flMemory > 0 && !capabilities.MemoryLimit {
|
|
//fmt.Fprintf(stdout, "WARNING: Your kernel does not support memory limit capabilities. Limitation discarded.\n")
|
|
//fmt.Fprintf(stdout, "WARNING: Your kernel does not support memory limit capabilities. Limitation discarded.\n")
|
|
@@ -174,6 +176,10 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if *flDetach && *flAutoRemove {
|
|
|
|
+ return nil, nil, cmd, fmt.Errorf("Conflicting options: -rm and -d")
|
|
|
|
+ }
|
|
|
|
+
|
|
var binds []string
|
|
var binds []string
|
|
|
|
|
|
// add any bind targets to the list of container volumes
|
|
// add any bind targets to the list of container volumes
|
|
@@ -242,6 +248,7 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig,
|
|
Binds: binds,
|
|
Binds: binds,
|
|
ContainerIDFile: *flContainerIDFile,
|
|
ContainerIDFile: *flContainerIDFile,
|
|
LxcConf: lxcConf,
|
|
LxcConf: lxcConf,
|
|
|
|
+ AutoRemove: *flAutoRemove,
|
|
}
|
|
}
|
|
|
|
|
|
if capabilities != nil && *flMemory > 0 && !capabilities.SwapLimit {
|
|
if capabilities != nil && *flMemory > 0 && !capabilities.SwapLimit {
|
|
@@ -818,7 +825,7 @@ func (container *Container) Start(hostConfig *HostConfig) error {
|
|
|
|
|
|
container.ToDisk()
|
|
container.ToDisk()
|
|
container.SaveHostConfig(hostConfig)
|
|
container.SaveHostConfig(hostConfig)
|
|
- go container.monitor()
|
|
|
|
|
|
+ go container.monitor(hostConfig)
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
@@ -948,7 +955,7 @@ func (container *Container) waitLxc() error {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func (container *Container) monitor() {
|
|
|
|
|
|
+func (container *Container) monitor(hostConfig *HostConfig) {
|
|
// Wait for the program to exit
|
|
// Wait for the program to exit
|
|
utils.Debugf("Waiting for process")
|
|
utils.Debugf("Waiting for process")
|
|
|
|
|
|
@@ -1018,6 +1025,11 @@ func (container *Container) monitor() {
|
|
// FIXME: why are we serializing running state to disk in the first place?
|
|
// FIXME: why are we serializing running state to disk in the first place?
|
|
//log.Printf("%s: Failed to dump configuration to the disk: %s", container.ID, err)
|
|
//log.Printf("%s: Failed to dump configuration to the disk: %s", container.ID, err)
|
|
}
|
|
}
|
|
|
|
+ if hostConfig != nil {
|
|
|
|
+ if hostConfig.AutoRemove {
|
|
|
|
+ container.runtime.Destroy(container)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
func (container *Container) kill() error {
|
|
func (container *Container) kill() error {
|