1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #11844 from jbarbier/cgroup-parent-42

Adding cgroup-parent option for docker build
This commit is contained in:
Arnaud Porterie 2015-05-05 14:46:47 -07:00
commit e960e4bb12
8 changed files with 60 additions and 13 deletions

View file

@ -58,6 +58,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
flCpuQuota := cmd.Int64([]string{"-cpu-quota"}, 0, "Limit the CPU CFS (Completely Fair Scheduler) quota") flCpuQuota := cmd.Int64([]string{"-cpu-quota"}, 0, "Limit the CPU CFS (Completely Fair Scheduler) quota")
flCPUSetCpus := cmd.String([]string{"-cpuset-cpus"}, "", "CPUs in which to allow execution (0-3, 0,1)") flCPUSetCpus := cmd.String([]string{"-cpuset-cpus"}, "", "CPUs in which to allow execution (0-3, 0,1)")
flCPUSetMems := cmd.String([]string{"-cpuset-mems"}, "", "MEMs in which to allow execution (0-3, 0,1)") flCPUSetMems := cmd.String([]string{"-cpuset-mems"}, "", "MEMs in which to allow execution (0-3, 0,1)")
flCgroupParent := cmd.String([]string{"-cgroup-parent"}, "", "Optional parent cgroup for the container")
cmd.Require(flag.Exact, 1) cmd.Require(flag.Exact, 1)
cmd.ParseFlags(args, true) cmd.ParseFlags(args, true)
@ -276,6 +277,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
v.Set("cpuquota", strconv.FormatInt(*flCpuQuota, 10)) v.Set("cpuquota", strconv.FormatInt(*flCpuQuota, 10))
v.Set("memory", strconv.FormatInt(memory, 10)) v.Set("memory", strconv.FormatInt(memory, 10))
v.Set("memswap", strconv.FormatInt(memorySwap, 10)) v.Set("memswap", strconv.FormatInt(memorySwap, 10))
v.Set("cgroupparent", *flCgroupParent)
v.Set("dockerfile", *dockerfileName) v.Set("dockerfile", *dockerfileName)

View file

@ -1301,6 +1301,7 @@ func (s *Server) postBuild(version version.Version, w http.ResponseWriter, r *ht
buildConfig.CpuQuota = int64ValueOrZero(r, "cpuquota") buildConfig.CpuQuota = int64ValueOrZero(r, "cpuquota")
buildConfig.CpuSetCpus = r.FormValue("cpusetcpus") buildConfig.CpuSetCpus = r.FormValue("cpusetcpus")
buildConfig.CpuSetMems = r.FormValue("cpusetmems") buildConfig.CpuSetMems = r.FormValue("cpusetmems")
buildConfig.CgroupParent = r.FormValue("cgroupparent")
// Job cancellation. Note: not all job types support this. // Job cancellation. Note: not all job types support this.
if closeNotifier, ok := w.(http.CloseNotifier); ok { if closeNotifier, ok := w.(http.CloseNotifier); ok {

View file

@ -126,6 +126,7 @@ type Builder struct {
cpuSetMems string cpuSetMems string
cpuShares int64 cpuShares int64
cpuQuota int64 cpuQuota int64
cgroupParent string
memory int64 memory int64
memorySwap int64 memorySwap int64

View file

@ -556,6 +556,7 @@ func (b *Builder) create() (*daemon.Container, error) {
CpuQuota: b.cpuQuota, CpuQuota: b.cpuQuota,
CpusetCpus: b.cpuSetCpus, CpusetCpus: b.cpuSetCpus,
CpusetMems: b.cpuSetMems, CpusetMems: b.cpuSetMems,
CgroupParent: b.cgroupParent,
Memory: b.memory, Memory: b.memory,
MemorySwap: b.memorySwap, MemorySwap: b.memorySwap,
} }

View file

@ -52,6 +52,7 @@ type Config struct {
CpuQuota int64 CpuQuota int64
CpuSetCpus string CpuSetCpus string
CpuSetMems string CpuSetMems string
CgroupParent string
AuthConfig *cliconfig.AuthConfig AuthConfig *cliconfig.AuthConfig
ConfigFile *cliconfig.ConfigFile ConfigFile *cliconfig.ConfigFile
@ -166,6 +167,7 @@ func Build(d *daemon.Daemon, buildConfig *Config) error {
cpuQuota: buildConfig.CpuQuota, cpuQuota: buildConfig.CpuQuota,
cpuSetCpus: buildConfig.CpuSetCpus, cpuSetCpus: buildConfig.CpuSetCpus,
cpuSetMems: buildConfig.CpuSetMems, cpuSetMems: buildConfig.CpuSetMems,
cgroupParent: buildConfig.CgroupParent,
memory: buildConfig.Memory, memory: buildConfig.Memory,
memorySwap: buildConfig.MemorySwap, memorySwap: buildConfig.MemorySwap,
cancelled: buildConfig.WaitCancelled(), cancelled: buildConfig.WaitCancelled(),

View file

@ -642,8 +642,9 @@ is returned by the `docker attach` command to its caller too:
-m, --memory="" Memory limit for all build containers -m, --memory="" Memory limit for all build containers
--memory-swap="" Total memory (memory + swap), `-1` to disable swap --memory-swap="" Total memory (memory + swap), `-1` to disable swap
-c, --cpu-shares CPU Shares (relative weight) -c, --cpu-shares CPU Shares (relative weight)
--cpuset-cpus="" CPUs in which to allow execution, e.g. `0-3`, `0,1`
--cpuset-mems="" MEMs in which to allow execution, e.g. `0-3`, `0,1` --cpuset-mems="" MEMs in which to allow execution, e.g. `0-3`, `0,1`
--cpuset-cpus="" CPUs in which to allow exection, e.g. `0-3`, `0,1`
--cgroup-parent="" Optional parent cgroup for the container
Builds Docker images from a Dockerfile and a "context". A build's context is Builds Docker images from a Dockerfile and a "context". A build's context is
the files located in the specified `PATH` or `URL`. The build process can the files located in the specified `PATH` or `URL`. The build process can
@ -862,6 +863,11 @@ you refer to it on the command line.
> children) for security reasons, and to ensure repeatable builds on remote > children) for security reasons, and to ensure repeatable builds on remote
> Docker hosts. This is also the reason why `ADD ../file` will not work. > Docker hosts. This is also the reason why `ADD ../file` will not work.
When `docker build` is run with the `--cgroup-parent` option the containers used
in the build will be run with the [corresponding `docker run`
flag](/reference/run/#specifying-custom-cgroups).
## commit ## commit
Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

View file

@ -465,6 +465,13 @@ Note:
You would have to write policy defining a `svirt_apache_t` type. You would have to write policy defining a `svirt_apache_t` type.
## Specifying custom cgroups
Using the `--cgroup-parent` flag, you can pass a specific cgroup to run a
container in. This allows you to create and manage cgroups on their own. You can
define custom resources for those cgroups and put containers under a common
parent group.
## Runtime constraints on resources ## Runtime constraints on resources
The operator can also adjust the performance parameters of the The operator can also adjust the performance parameters of the

View file

@ -5322,3 +5322,30 @@ func (s *DockerSuite) TestBuildEmptyStringVolume(c *check.C) {
} }
} }
func (s *DockerSuite) TestBuildContainerWithCgroupParent(c *check.C) {
testRequires(c, NativeExecDriver)
testRequires(c, SameHostDaemon)
defer deleteImages()
cgroupParent := "test"
data, err := ioutil.ReadFile("/proc/self/cgroup")
if err != nil {
c.Fatalf("failed to read '/proc/self/cgroup - %v", err)
}
selfCgroupPaths := parseCgroupPaths(string(data))
_, found := selfCgroupPaths["memory"]
if !found {
c.Fatalf("unable to find self cpu cgroup path. CgroupsPath: %v", selfCgroupPaths)
}
cmd := exec.Command(dockerBinary, "build", "--cgroup-parent", cgroupParent, "-")
cmd.Stdin = strings.NewReader(`
FROM busybox
RUN cat /proc/self/cgroup
`)
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err)
}
}