Ignore negative or zero quota
@@ -288,7 +288,12 @@ public class DockerImpl implements Docker {
}
private static ContainerResources containerResourcesFromHostConfig(HostConfig hostConfig) {
- final double cpus = hostConfig.getCpuPeriod() > 0 ?
+ // Docker keeps an internal state of what the period and quota are: in cgroups, the quota is always set
+ // (default is 100000), but docker will report it as 0 unless explicitly set by the user.
+ // This may lead to a state where the quota is set, but period is 0 (accord to docker), which will
+ // mess up the calculation below. This can only happen if someone sets it manually, since this class
+ // will always set both quota and period.
+ final double cpus = hostConfig.getCpuQuota() > 0 ?
(double) hostConfig.getCpuQuota() / hostConfig.getCpuPeriod() : 0;
return new ContainerResources(cpus, hostConfig.getCpuShares(), hostConfig.getMemory());
}
