|
|
@@ -2,13 +2,13 @@ package cn.reghao.autodop.common.docker;
|
|
|
|
|
|
import cn.reghao.autodop.common.docker.api.Docker;
|
|
|
import cn.reghao.autodop.common.docker.po.Config;
|
|
|
-import cn.reghao.autodop.common.docker.po.result.ContainerInfo;
|
|
|
import cn.reghao.autodop.common.util.ExceptionUtil;
|
|
|
import cn.reghao.jdkutil.text.TextFile;
|
|
|
import com.github.dockerjava.api.DockerClient;
|
|
|
import com.github.dockerjava.api.command.*;
|
|
|
import com.github.dockerjava.api.model.Container;
|
|
|
import com.github.dockerjava.api.model.HostConfig;
|
|
|
+import com.github.dockerjava.api.model.RestartPolicy;
|
|
|
import com.github.dockerjava.core.DefaultDockerClientConfig;
|
|
|
import com.github.dockerjava.core.DockerClientConfig;
|
|
|
import com.github.dockerjava.core.DockerClientImpl;
|
|
|
@@ -19,7 +19,6 @@ import com.github.dockerjava.transport.DockerHttpClient;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.time.Duration;
|
|
|
-import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
|
|
|
@@ -154,10 +153,14 @@ public class DockerImpl implements Docker {
|
|
|
public String createAndRun(String containerName, Config config) throws DockerException {
|
|
|
stopAndDelete(containerName);
|
|
|
|
|
|
- HostConfig hostConfig;
|
|
|
+ HostConfig hostConfig = HostConfig.newHostConfig()
|
|
|
+ .withNetworkMode("host")
|
|
|
+ .withRestartPolicy(RestartPolicy.onFailureRestart(3));
|
|
|
+
|
|
|
CreateContainerResponse response = dockerClient.createContainerCmd(config.getImage())
|
|
|
.withName(containerName)
|
|
|
- .withEnv(Collections.emptyList())
|
|
|
+ .withHostConfig(hostConfig)
|
|
|
+ .withEnv(config.getEnv())
|
|
|
.exec();
|
|
|
|
|
|
String containerId1 = response.getId();
|