|
@@ -58,25 +58,26 @@ type Container struct {
|
|
|
}
|
|
|
|
|
|
type Config struct {
|
|
|
- Hostname string
|
|
|
- User string
|
|
|
- Memory int64 // Memory limit (in bytes)
|
|
|
- MemorySwap int64 // Total memory usage (memory + swap); set `-1' to disable swap
|
|
|
- CpuShares int64 // CPU shares (relative weight vs. other containers)
|
|
|
- AttachStdin bool
|
|
|
- AttachStdout bool
|
|
|
- AttachStderr bool
|
|
|
- PortSpecs []string
|
|
|
- Tty bool // Attach standard streams to a tty, including stdin if it is not closed.
|
|
|
- OpenStdin bool // Open stdin
|
|
|
- StdinOnce bool // If true, close stdin after the 1 attached client disconnects.
|
|
|
- Env []string
|
|
|
- Cmd []string
|
|
|
- Dns []string
|
|
|
- Image string // Name of the image as it was passed by the operator (eg. could be symbolic)
|
|
|
- Volumes map[string]struct{}
|
|
|
- VolumesFrom string
|
|
|
- Entrypoint []string
|
|
|
+ Hostname string
|
|
|
+ User string
|
|
|
+ Memory int64 // Memory limit (in bytes)
|
|
|
+ MemorySwap int64 // Total memory usage (memory + swap); set `-1' to disable swap
|
|
|
+ CpuShares int64 // CPU shares (relative weight vs. other containers)
|
|
|
+ AttachStdin bool
|
|
|
+ AttachStdout bool
|
|
|
+ AttachStderr bool
|
|
|
+ PortSpecs []string
|
|
|
+ Tty bool // Attach standard streams to a tty, including stdin if it is not closed.
|
|
|
+ OpenStdin bool // Open stdin
|
|
|
+ StdinOnce bool // If true, close stdin after the 1 attached client disconnects.
|
|
|
+ Env []string
|
|
|
+ Cmd []string
|
|
|
+ Dns []string
|
|
|
+ Image string // Name of the image as it was passed by the operator (eg. could be symbolic)
|
|
|
+ Volumes map[string]struct{}
|
|
|
+ VolumesFrom string
|
|
|
+ Entrypoint []string
|
|
|
+ NetworkDisabled bool
|
|
|
}
|
|
|
|
|
|
type HostConfig struct {
|
|
@@ -106,6 +107,7 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig,
|
|
|
flTty := cmd.Bool("t", false, "Allocate a pseudo-tty")
|
|
|
flMemory := cmd.Int64("m", 0, "Memory limit (in bytes)")
|
|
|
flContainerIDFile := cmd.String("cidfile", "", "Write the container ID to the file")
|
|
|
+ flNetwork := cmd.Bool("n", true, "Enable networking for this container")
|
|
|
|
|
|
if capabilities != nil && *flMemory > 0 && !capabilities.MemoryLimit {
|
|
|
//fmt.Fprintf(stdout, "WARNING: Your kernel does not support memory limit capabilities. Limitation discarded.\n")
|
|
@@ -174,23 +176,24 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig,
|
|
|
}
|
|
|
|
|
|
config := &Config{
|
|
|
- Hostname: *flHostname,
|
|
|
- PortSpecs: flPorts,
|
|
|
- User: *flUser,
|
|
|
- Tty: *flTty,
|
|
|
- OpenStdin: *flStdin,
|
|
|
- Memory: *flMemory,
|
|
|
- CpuShares: *flCpuShares,
|
|
|
- AttachStdin: flAttach.Get("stdin"),
|
|
|
- AttachStdout: flAttach.Get("stdout"),
|
|
|
- AttachStderr: flAttach.Get("stderr"),
|
|
|
- Env: flEnv,
|
|
|
- Cmd: runCmd,
|
|
|
- Dns: flDns,
|
|
|
- Image: image,
|
|
|
- Volumes: flVolumes,
|
|
|
- VolumesFrom: *flVolumesFrom,
|
|
|
- Entrypoint: entrypoint,
|
|
|
+ Hostname: *flHostname,
|
|
|
+ PortSpecs: flPorts,
|
|
|
+ User: *flUser,
|
|
|
+ Tty: *flTty,
|
|
|
+ NetworkDisabled: !*flNetwork,
|
|
|
+ OpenStdin: *flStdin,
|
|
|
+ Memory: *flMemory,
|
|
|
+ CpuShares: *flCpuShares,
|
|
|
+ AttachStdin: flAttach.Get("stdin"),
|
|
|
+ AttachStdout: flAttach.Get("stdout"),
|
|
|
+ AttachStderr: flAttach.Get("stderr"),
|
|
|
+ Env: flEnv,
|
|
|
+ Cmd: runCmd,
|
|
|
+ Dns: flDns,
|
|
|
+ Image: image,
|
|
|
+ Volumes: flVolumes,
|
|
|
+ VolumesFrom: *flVolumesFrom,
|
|
|
+ Entrypoint: entrypoint,
|
|
|
}
|
|
|
hostConfig := &HostConfig{
|
|
|
Binds: binds,
|
|
@@ -511,8 +514,12 @@ func (container *Container) Start(hostConfig *HostConfig) error {
|
|
|
if err := container.EnsureMounted(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- if err := container.allocateNetwork(); err != nil {
|
|
|
- return err
|
|
|
+ if container.runtime.networkManager.disabled {
|
|
|
+ container.Config.NetworkDisabled = true
|
|
|
+ } else {
|
|
|
+ if err := container.allocateNetwork(); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Make sure the config is compatible with the current kernel
|
|
@@ -626,7 +633,9 @@ func (container *Container) Start(hostConfig *HostConfig) error {
|
|
|
}
|
|
|
|
|
|
// Networking
|
|
|
- params = append(params, "-g", container.network.Gateway.String())
|
|
|
+ if !container.Config.NetworkDisabled {
|
|
|
+ params = append(params, "-g", container.network.Gateway.String())
|
|
|
+ }
|
|
|
|
|
|
// User
|
|
|
if container.Config.User != "" {
|
|
@@ -728,6 +737,10 @@ func (container *Container) StderrPipe() (io.ReadCloser, error) {
|
|
|
}
|
|
|
|
|
|
func (container *Container) allocateNetwork() error {
|
|
|
+ if container.Config.NetworkDisabled {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
iface, err := container.runtime.networkManager.Allocate()
|
|
|
if err != nil {
|
|
|
return err
|
|
@@ -754,6 +767,9 @@ func (container *Container) allocateNetwork() error {
|
|
|
}
|
|
|
|
|
|
func (container *Container) releaseNetwork() {
|
|
|
+ if container.Config.NetworkDisabled {
|
|
|
+ return
|
|
|
+ }
|
|
|
container.network.Release()
|
|
|
container.network = nil
|
|
|
container.NetworkSettings = &NetworkSettings{}
|