Allow setting ulimits for containers
Signed-off-by: Brian Goff <cpuguy83@gmail.com> Upstream-commit: 3f39050637d454e9ee8075153a917c8bfccb5bae Component: engine
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/docker/docker/daemon/networkdriver"
|
||||
"github.com/docker/docker/opts"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -44,6 +45,7 @@ type Config struct {
|
||||
Context map[string][]string
|
||||
TrustKeyPath string
|
||||
Labels []string
|
||||
Ulimits map[string]*ulimit.Ulimit
|
||||
}
|
||||
|
||||
// InstallFlags adds command-line options to the top-level flag parser for
|
||||
@@ -75,6 +77,8 @@ func (config *Config) InstallFlags() {
|
||||
opts.IPListVar(&config.Dns, []string{"#dns", "-dns"}, "DNS server to use")
|
||||
opts.DnsSearchListVar(&config.DnsSearch, []string{"-dns-search"}, "DNS search domains to use")
|
||||
opts.LabelListVar(&config.Labels, []string{"-label"}, "Set key=value labels to the daemon")
|
||||
config.Ulimits = make(map[string]*ulimit.Ulimit)
|
||||
opts.UlimitMapVar(config.Ulimits, []string{"-default-ulimit"}, "Set default ulimits for containers")
|
||||
}
|
||||
|
||||
func getDefaultNetworkMtu() int {
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/docker/docker/pkg/networkfs/resolvconf"
|
||||
"github.com/docker/docker/pkg/promise"
|
||||
"github.com/docker/docker/pkg/symlink"
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
@@ -276,11 +277,34 @@ func populateCommand(c *Container, env []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var rlimits []*ulimit.Rlimit
|
||||
ulimits := c.hostConfig.Ulimits
|
||||
|
||||
// Merge ulimits with daemon defaults
|
||||
ulIdx := make(map[string]*ulimit.Ulimit)
|
||||
for _, ul := range ulimits {
|
||||
ulIdx[ul.Name] = ul
|
||||
}
|
||||
for name, ul := range c.daemon.config.Ulimits {
|
||||
if _, exists := ulIdx[name]; !exists {
|
||||
ulimits = append(ulimits, ul)
|
||||
}
|
||||
}
|
||||
|
||||
for _, limit := range ulimits {
|
||||
rl, err := limit.GetRlimit()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rlimits = append(rlimits, rl)
|
||||
}
|
||||
|
||||
resources := &execdriver.Resources{
|
||||
Memory: c.Config.Memory,
|
||||
MemorySwap: c.Config.MemorySwap,
|
||||
CpuShares: c.Config.CpuShares,
|
||||
Cpuset: c.Config.Cpuset,
|
||||
Rlimits: rlimits,
|
||||
}
|
||||
|
||||
processConfig := execdriver.ProcessConfig{
|
||||
|
||||
@@ -2,14 +2,16 @@ package execdriver
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/docker/docker/daemon/execdriver/native/template"
|
||||
"github.com/docker/libcontainer"
|
||||
"github.com/docker/libcontainer/devices"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/daemon/execdriver/native/template"
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
"github.com/docker/libcontainer"
|
||||
"github.com/docker/libcontainer/devices"
|
||||
)
|
||||
|
||||
// Context is a generic key value pair that allows
|
||||
@@ -99,10 +101,11 @@ type NetworkInterface struct {
|
||||
}
|
||||
|
||||
type Resources struct {
|
||||
Memory int64 `json:"memory"`
|
||||
MemorySwap int64 `json:"memory_swap"`
|
||||
CpuShares int64 `json:"cpu_shares"`
|
||||
Cpuset string `json:"cpuset"`
|
||||
Memory int64 `json:"memory"`
|
||||
MemorySwap int64 `json:"memory_swap"`
|
||||
CpuShares int64 `json:"cpu_shares"`
|
||||
Cpuset string `json:"cpuset"`
|
||||
Rlimits []*ulimit.Rlimit `json:"rlimits"`
|
||||
}
|
||||
|
||||
type ResourceStats struct {
|
||||
|
||||
@@ -58,6 +58,8 @@ func (d *driver) createContainer(c *execdriver.Command) (*libcontainer.Config, e
|
||||
return nil, err
|
||||
}
|
||||
|
||||
d.setupRlimits(container, c)
|
||||
|
||||
cmds := make(map[string]*exec.Cmd)
|
||||
d.Lock()
|
||||
for k, v := range d.activeContainers {
|
||||
@@ -172,6 +174,16 @@ func (d *driver) setCapabilities(container *libcontainer.Config, c *execdriver.C
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *driver) setupRlimits(container *libcontainer.Config, c *execdriver.Command) {
|
||||
if c.Resources == nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, rlimit := range c.Resources.Rlimits {
|
||||
container.Rlimits = append(container.Rlimits, libcontainer.Rlimit((*rlimit)))
|
||||
}
|
||||
}
|
||||
|
||||
func (d *driver) setupMounts(container *libcontainer.Config, c *execdriver.Command) error {
|
||||
for _, m := range c.Mounts {
|
||||
container.MountConfig.Mounts = append(container.MountConfig.Mounts, &mount.Mount{
|
||||
|
||||
@@ -74,6 +74,7 @@ func (daemon *Daemon) setHostConfig(container *Container, hostConfig *runconfig.
|
||||
if err := daemon.RegisterLinks(container, hostConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
container.hostConfig = hostConfig
|
||||
container.toDisk()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user