зеркало из https://github.com/microsoft/docker.git
Add capabilities check to allow docker to run on kernel that does not have all options
This commit is contained in:
Родитель
003622c8b6
Коммит
640efc2ed2
|
@ -907,7 +907,7 @@ func (srv *Server) CmdTag(stdin io.ReadCloser, stdout io.Writer, args ...string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) CmdRun(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error {
|
func (srv *Server) CmdRun(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error {
|
||||||
config, err := ParseRun(args, stdout)
|
config, err := ParseRun(args, stdout, srv.runtime.capabilities)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
12
container.go
12
container.go
|
@ -66,7 +66,7 @@ type Config struct {
|
||||||
Image string // Name of the image as it was passed by the operator (eg. could be symbolic)
|
Image string // Name of the image as it was passed by the operator (eg. could be symbolic)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseRun(args []string, stdout io.Writer) (*Config, error) {
|
func ParseRun(args []string, stdout io.Writer, capabilities *Capabilities) (*Config, error) {
|
||||||
cmd := rcli.Subcmd(stdout, "run", "[OPTIONS] IMAGE COMMAND [ARG...]", "Run a command in a new container")
|
cmd := rcli.Subcmd(stdout, "run", "[OPTIONS] IMAGE COMMAND [ARG...]", "Run a command in a new container")
|
||||||
if len(args) > 0 && args[0] != "--help" {
|
if len(args) > 0 && args[0] != "--help" {
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
|
@ -81,8 +81,8 @@ func ParseRun(args []string, stdout io.Writer) (*Config, error) {
|
||||||
flTty := cmd.Bool("t", false, "Allocate a pseudo-tty")
|
flTty := cmd.Bool("t", false, "Allocate a pseudo-tty")
|
||||||
flMemory := cmd.Int64("m", 0, "Memory limit (in bytes)")
|
flMemory := cmd.Int64("m", 0, "Memory limit (in bytes)")
|
||||||
|
|
||||||
if *flMemory > 0 && NO_MEMORY_LIMIT {
|
if *flMemory > 0 && !capabilities.MemoryLimit {
|
||||||
fmt.Fprintf(stdout, "WARNING: This version of docker has been compiled without memory limit support. Discarding -m.")
|
fmt.Fprintf(stdout, "WARNING: Your kernel does not support memory limit capabilities. Limitation discarded.\n")
|
||||||
*flMemory = 0
|
*flMemory = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,6 +135,12 @@ func ParseRun(args []string, stdout io.Writer) (*Config, error) {
|
||||||
Dns: flDns,
|
Dns: flDns,
|
||||||
Image: image,
|
Image: image,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *flMemory > 0 && !capabilities.SwapLimit {
|
||||||
|
fmt.Fprintf(stdout, "WARNING: Your kernel does not support swap limit capabilities. Limitation discarded.\n")
|
||||||
|
config.MemorySwap = -1
|
||||||
|
}
|
||||||
|
|
||||||
// When allocating stdin in attached mode, close stdin at client disconnect
|
// When allocating stdin in attached mode, close stdin at client disconnect
|
||||||
if config.OpenStdin && config.AttachStdin {
|
if config.OpenStdin && config.AttachStdin {
|
||||||
config.StdinOnce = true
|
config.StdinOnce = true
|
||||||
|
|
14
runtime.go
14
runtime.go
|
@ -15,6 +15,11 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Capabilities struct {
|
||||||
|
MemoryLimit bool
|
||||||
|
SwapLimit bool
|
||||||
|
}
|
||||||
|
|
||||||
type Runtime struct {
|
type Runtime struct {
|
||||||
root string
|
root string
|
||||||
repository string
|
repository string
|
||||||
|
@ -24,6 +29,7 @@ type Runtime struct {
|
||||||
repositories *TagStore
|
repositories *TagStore
|
||||||
authConfig *auth.AuthConfig
|
authConfig *auth.AuthConfig
|
||||||
idIndex *TruncIndex
|
idIndex *TruncIndex
|
||||||
|
capabilities *Capabilities
|
||||||
kernelVersion *KernelVersionInfo
|
kernelVersion *KernelVersionInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,6 +305,13 @@ func NewRuntime() (*Runtime, error) {
|
||||||
log.Printf("WARNING: You are running linux kernel version %s, which might be unstable running docker. Please upgrade your kernel to 3.8.0.", k.String())
|
log.Printf("WARNING: You are running linux kernel version %s, which might be unstable running docker. Please upgrade your kernel to 3.8.0.", k.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err1 := ioutil.ReadFile("/sys/fs/cgroup/memory/memory.limit_in_bytes")
|
||||||
|
_, err2 := ioutil.ReadFile("/sys/fs/cgroup/memory/memory.soft_limit_in_bytes")
|
||||||
|
runtime.capabilities.MemoryLimit = err1 == nil && err2 == nil
|
||||||
|
|
||||||
|
_, err = ioutil.ReadFile("/sys/fs/cgroup/memory/memeory.memsw.limit_in_bytes")
|
||||||
|
runtime.capabilities.SwapLimit = err == nil
|
||||||
|
|
||||||
return runtime, nil
|
return runtime, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,6 +351,7 @@ func NewRuntimeFromDirectory(root string) (*Runtime, error) {
|
||||||
repositories: repositories,
|
repositories: repositories,
|
||||||
authConfig: authConfig,
|
authConfig: authConfig,
|
||||||
idIndex: NewTruncIndex(),
|
idIndex: NewTruncIndex(),
|
||||||
|
capabilities: &Capabilities{},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := runtime.restore(); err != nil {
|
if err := runtime.restore(); err != nil {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче