mirror of https://github.com/docker/compose.git
backend.local: Add CPU limits
Signed-off-by: Chris Crone <christopher.crone@docker.com>
This commit is contained in:
parent
42f31d3129
commit
47aa069a3d
|
@ -171,6 +171,7 @@ func containerJSONToHostConfig(m *types.ContainerJSON) *containers.HostConfig {
|
||||||
return &containers.HostConfig{
|
return &containers.HostConfig{
|
||||||
AutoRemove: m.HostConfig.AutoRemove,
|
AutoRemove: m.HostConfig.AutoRemove,
|
||||||
RestartPolicy: restartPolicy,
|
RestartPolicy: restartPolicy,
|
||||||
|
CPULimit: float64(m.HostConfig.Resources.NanoCPUs) / 1e9,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,6 +217,9 @@ func (ms *local) Run(ctx context.Context, r containers.ContainerConfig) error {
|
||||||
hostConfig := &container.HostConfig{
|
hostConfig := &container.HostConfig{
|
||||||
PortBindings: hostBindings,
|
PortBindings: hostBindings,
|
||||||
AutoRemove: r.AutoRemove,
|
AutoRemove: r.AutoRemove,
|
||||||
|
Resources: container.Resources{
|
||||||
|
NanoCPUs: int64(r.CPULimit * 1e9),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
created, err := ms.apiClient.ContainerCreate(ctx, containerConfig, hostConfig, nil, r.ID)
|
created, err := ms.apiClient.ContainerCreate(ctx, containerConfig, hostConfig, nil, r.ID)
|
||||||
|
|
|
@ -52,6 +52,9 @@ func TestToHostConfig(t *testing.T) {
|
||||||
RestartPolicy: container.RestartPolicy{
|
RestartPolicy: container.RestartPolicy{
|
||||||
Name: "",
|
Name: "",
|
||||||
},
|
},
|
||||||
|
Resources: container.Resources{
|
||||||
|
NanoCPUs: 750000000,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
m := &types.ContainerJSON{
|
m := &types.ContainerJSON{
|
||||||
|
@ -65,6 +68,7 @@ func TestToHostConfig(t *testing.T) {
|
||||||
res := &containers.HostConfig{
|
res := &containers.HostConfig{
|
||||||
AutoRemove: true,
|
AutoRemove: true,
|
||||||
RestartPolicy: containers.RestartPolicyNone,
|
RestartPolicy: containers.RestartPolicyNone,
|
||||||
|
CPULimit: 0.75,
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, hc, res)
|
assert.DeepEqual(t, hc, res)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue