|
|
@@ -228,6 +228,20 @@ public class DockerImpl implements Docker {
|
|
|
return dockerClient.inspectContainerCmd(containerId).exec();
|
|
|
}
|
|
|
|
|
|
+ public void createAndRun() {
|
|
|
+ String image = "";
|
|
|
+ CreateContainerResponse container = dockerClient.createContainerCmd(image)
|
|
|
+ .withHostConfig(HostConfig.newHostConfig()
|
|
|
+ .withMemory(1024 * 1024 * 1024L) // 限制 1GB 内存
|
|
|
+ .withMemoryReservation(512 * 1024 * 1024L) // 保证 512MB 内存
|
|
|
+ .withCpuQuota(50000L) // 限制使用 0.5 核 (周期默认为 100000)
|
|
|
+ .withBlkioWeight(500) // 设置磁盘 IO 权重
|
|
|
+ .withNetworkMode("host")
|
|
|
+ .withRestartPolicy(RestartPolicy.noRestart())
|
|
|
+ )
|
|
|
+ .exec();
|
|
|
+ }
|
|
|
+
|
|
|
public void runAndRm(cn.reghao.bnt.common.docker.model.Config containerConfig) throws Exception {
|
|
|
String image = containerConfig.getImage();
|
|
|
CreateContainerCmd createContainerCmd = dockerClient.createContainerCmd(image).withCmd("rm");
|