Repository: docker-java/docker-java
Pull request #272 (2015-07-16 20:33:29)

remove withHostConfig() from create container command


Patch:
diff --git a/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java b/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java
index 37177441..ab4ac9fe 100644
--- a/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java
+++ b/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java
@@ -8,12 +8,12 @@ import com.github.dockerjava.api.model.Bind;
 import com.github.dockerjava.api.model.Capability;
 import com.github.dockerjava.api.model.Device;
 import com.github.dockerjava.api.model.ExposedPort;
-import com.github.dockerjava.api.model.HostConfig;
 import com.github.dockerjava.api.model.Link;
 import com.github.dockerjava.api.model.LxcConf;
 import com.github.dockerjava.api.model.PortBinding;
 import com.github.dockerjava.api.model.Ports;
 import com.github.dockerjava.api.model.RestartPolicy;
+import com.github.dockerjava.api.model.Ulimit;
 import com.github.dockerjava.api.model.Volume;
 import com.github.dockerjava.api.model.VolumesFrom;
 
@@ -77,8 +77,6 @@ public interface CreateContainerCmd extends SyncDockerCmd<CreateContainerRespons
 
     public String[] getExtraHosts();
 
-    public HostConfig getHostConfig();
-
     public String getHostName();
 
     public String getDomainName();
@@ -113,6 +111,8 @@ public interface CreateContainerCmd extends SyncDockerCmd<CreateContainerRespons
 
     public String getWorkingDir();
 
+    public Ulimit[] getUlimits();
+
     public boolean isAttachStderr();
 
     public boolean isAttachStdin();
@@ -207,8 +207,6 @@ public interface CreateContainerCmd extends SyncDockerCmd<CreateContainerRespons
      */
     public CreateContainerCmd withExtraHosts(String... extraHosts);
 
-    public CreateContainerCmd withHostConfig(HostConfig hostConfig);
-
     public CreateContainerCmd withHostName(String hostName);
 
     public CreateContainerCmd withDomainName(String domainName);
@@ -282,6 +280,12 @@ public interface CreateContainerCmd extends SyncDockerCmd<CreateContainerRespons
 
     public CreateContainerCmd withMacAddress(String macAddress);
 
+    public CreateContainerCmd withUlimits(Ulimit[] ulimits);
+
+    public CreateContainerCmd withReadonlyRootfs(boolean readonlyRootfs);
+
+    public CreateContainerCmd withContainerIDFile(String containerIDFile);
+
     /**
      * @return
      */
diff --git a/src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java b/src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java
index 32851321..11fb50b5 100644
--- a/src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java
+++ b/src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java
@@ -23,6 +23,7 @@ import com.github.dockerjava.api.model.LxcConf;
 import com.github.dockerjava.api.model.PortBinding;
 import com.github.dockerjava.api.model.Ports;
 import com.github.dockerjava.api.model.RestartPolicy;
+import com.github.dockerjava.api.model.Ulimit;
 import com.github.dockerjava.api.model.Volume;
 import com.github.dockerjava.api.model.Volumes;
 import com.github.dockerjava.api.model.VolumesFrom;
@@ -147,6 +148,11 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
         return hostConfig.getBinds();
     }
 
+    @Override
+    public Integer getBlkioWeight() {
+        return blkioWeight;
+    }
+
     @Override
     public Capability[] getCapAdd() {
         return hostConfig.getCapAdd();
@@ -162,14 +168,8 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
         return cmd;
     }
 
-    @Override
-    public String getCpuset() {
-        return cpuset;
-    }
-
-    @Override
-    public int getCpuShares() {
-        return cpuShares;
+    public String getContainerIDFile() {
+        return hostConfig.getContainerIDFile();
     }
 
     @Override
@@ -178,18 +178,18 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
     }
 
     @Override
-    public String getCpusetMems() {
-        return cpusetMems;
+    public String getCpuset() {
+        return cpuset;
     }
 
     @Override
-    public Integer getBlkioWeight() {
-        return blkioWeight;
+    public String getCpusetMems() {
+        return cpusetMems;
     }
 
     @Override
-    public Boolean isOomKillDisable() {
-        return oomKillDisable;
+    public int getCpuShares() {
+        return cpuShares;
     }
 
     @Override
@@ -210,6 +210,11 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
         return hostConfig.getDnsSearch();
     }
 
+    @Override
+    public String getDomainName() {
+        return domainName;
+    }
+
     @Override
     public String[] getEntrypoint() {
         return entrypoint;
@@ -232,21 +237,11 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
         return hostConfig.getExtraHosts();
     }
 
-    @Override
-    public HostConfig getHostConfig() {
-        return hostConfig;
-    }
-
     @Override
     public String getHostName() {
         return hostName;
     }
 
-    @Override
-    public String getDomainName() {
-        return domainName;
-    }
-
     @Override
     public String getImage() {
         return image;
@@ -254,14 +249,14 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
 
     @Override
     @JsonIgnore
-    public Link[] getLinks() {
-        return hostConfig.getLinks();
+    public Map<String, String> getLabels() {
+        return labels;
     }
 
     @Override
     @JsonIgnore
-    public Map<String, String> getLabels() {
-        return labels;
+    public Link[] getLinks() {
+        return hostConfig.getLinks();
     }
 
     @Override
@@ -312,6 +307,11 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
         return hostConfig.getRestartPolicy();
     }
 
+    @Override
+    public Ulimit[] getUlimits() {
+        return hostConfig.getUlimits();
+    }
+
     @Override
     public String getUser() {
         return user;
@@ -354,6 +354,11 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
         return networkDisabled;
     }
 
+    @Override
+    public Boolean isOomKillDisable() {
+        return oomKillDisable;
+    }
+
     @Override
     @JsonIgnore
     public Boolean isPrivileged() {
@@ -366,6 +371,10 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
         return hostConfig.isPublishAllPorts();
     }
 
+    public boolean isReadonlyRootfs() {
+        return hostConfig.isReadonlyRootfs();
+    }
+
     @Override
     public boolean isStdInOnce() {
         return stdInOnce;
@@ -407,133 +416,139 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
 
     @Override
     public CreateContainerCmd withBinds(Bind... binds) {
+        checkNotNull(binds, "binds was not specified");
         hostConfig.setBinds(binds);
         return this;
     }
 
+    @Override
+    public CreateContainerCmd withBlkioWeight(Integer blkioWeight) {
+        checkNotNull(blkioWeight, "blkioWeight was not specified");
+        this.blkioWeight = blkioWeight;
+        return null;
+    }
+
     @Override
     public CreateContainerCmd withCapAdd(Capability... capAdd) {
+        checkNotNull(capAdd, "capAdd was not specified");
         hostConfig.setCapAdd(capAdd);
         return this;
     }
 
     @Override
     public CreateContainerCmd withCapDrop(Capability... capDrop) {
+        checkNotNull(capDrop, "capDrop was not specified");
         hostConfig.setCapDrop(capDrop);
         return this;
     }
 
     @Override
     public CreateContainerCmdImpl withCmd(String... cmd) {
+        checkNotNull(cmd, "cmd was not specified");
         this.cmd = cmd;
         return this;
     }
 
     @Override
-    public CreateContainerCmdImpl withCpuset(String cpuset) {
-        this.cpuset = cpuset;
+    public CreateContainerCmd withContainerIDFile(String containerIDFile) {
+        checkNotNull(containerIDFile, "no containerIDFile was specified");
+        hostConfig.setContainerIDFile(containerIDFile);
         return this;
     }
 
     @Override
-    public CreateContainerCmdImpl withCpuShares(int cpuShares) {
-        this.cpuShares = cpuShares;
+    public CreateContainerCmd withCpuPeriod(Integer cpuPeriod) {
+        checkNotNull(cpuPeriod, "cpuPeriod was not specified");
+        this.cpuPeriod = cpuPeriod;
         return this;
     }
 
     @Override
-    public CreateContainerCmd withCpuPeriod(Integer cpuPeriod) {
-        this.cpuPeriod = cpuPeriod;
+    public CreateContainerCmdImpl withCpuset(String cpuset) {
+        checkNotNull(cpuset, "cpuset was not specified");
+        this.cpuset = cpuset;
         return this;
     }
 
     @Override
     public CreateContainerCmd withCpusetMems(String cpusetMems) {
+        checkNotNull(cpusetMems, "cpusetMems was not specified");
         this.cpusetMems = cpusetMems;
         return null;
     }
 
     @Override
-    public CreateContainerCmd withBlkioWeight(Integer blkioWeight) {
-        this.blkioWeight = blkioWeight;
-        return null;
-    }
-
-    @Override
-    public CreateContainerCmd withOomKillDisable(Boolean oomKillDisable) {
-        this.oomKillDisable = oomKillDisable;
-        return null;
+    public CreateContainerCmdImpl withCpuShares(int cpuShares) {
+        this.cpuShares = cpuShares;
+        return this;
     }
 
     @Override
     public CreateContainerCmd withDevices(Device... devices) {
+        checkNotNull(devices, "devices was not specified");
         this.hostConfig.setDevices(devices);
         return this;
     }
 
-    @Override
-    public CreateContainerCmdImpl withNetworkDisabled(boolean disableNetwork) {
-        this.networkDisabled = disableNetwork;
-        return this;
-    }
-
     @Override
     public CreateContainerCmdImpl withDns(String... dns) {
+        checkNotNull(dns, "dns was not specified");
         this.hostConfig.setDns(dns);
         return this;
     }
 
     @Override
     public CreateContainerCmd withDnsSearch(String... dnsSearch) {
+        checkNotNull(dnsSearch, "dnsSearch was not specified");
         this.hostConfig.setDnsSearch(dnsSearch);
         return this;
     }
 
+    @Override
+    public CreateContainerCmdImpl withDomainName(String domainName) {
+        checkNotNull(domainName, "no domainName was specified");
+        this.domainName = domainName;
+        return this;
+    }
+
     @Override
     public CreateContainerCmdImpl withEntrypoint(String... entrypoint) {
+        checkNotNull(entrypoint, "entrypoint was not specified");
         this.entrypoint = entrypoint;
         return this;
     }
 
     @Override
     public CreateContainerCmdImpl withEnv(String... env) {
+        checkNotNull(env, "env was not specified");
         this.env = env;
         return this;
     }
 
     @Override
     public CreateContainerCmdImpl withExposedPorts(ExposedPort... exposedPorts) {
+        checkNotNull(exposedPorts, "exposedPorts was not specified");
         this.exposedPorts = new ExposedPorts(exposedPorts);
         return this;
     }
 
     @Override
     public CreateContainerCmd withExtraHosts(String... extraHosts) {
+        checkNotNull(extraHosts, "extraHosts was not specified");
         this.hostConfig.setExtraHosts(extraHosts);
         return this;
     }
 
-    @Override
-    public CreateContainerCmd withHostConfig(HostConfig hostConfig) {
-        checkNotNull(hostConfig, "no host config was specified");
-        this.hostConfig = hostConfig;
-        return this;
-    }
-
     @Override
     public CreateContainerCmdImpl withHostName(String hostName) {
+        checkNotNull(hostConfig, "no hostName was specified");
         this.hostName = hostName;
         return this;
     }
 
-    @Override
-    public CreateContainerCmdImpl withDomainName(String domainName) {
-        this.domainName = domainName;
-        return this;
-    }
-
     @Override
     public CreateContainerCmdImpl withImage(String image) {
+        checkNotNull(image, "no image was specified");
         this.image = image;
         return this;
     }
@@ -561,6 +576,7 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
 
     @Override
     public CreateContainerCmdImpl withMacAddress(String macAddress) {
+        checkNotNull(macAddress, "macAddress was not specified");
         this.macAddress = macAddress;
         return this;
     }
@@ -584,6 +600,12 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
         return this;
     }
 
+    @Override
+    public CreateContainerCmdImpl withNetworkDisabled(boolean disableNetwork) {
+        this.networkDisabled = disableNetwork;
+        return this;
+    }
+
     @Override
     public CreateContainerCmd withNetworkMode(String networkMode) {
         checkNotNull(networkMode, "networkMode was not specified");
@@ -591,6 +613,13 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
         return this;
     }
 
+    @Override
+    public CreateContainerCmd withOomKillDisable(Boolean oomKillDisable) {
+        checkNotNull(oomKillDisable, "oomKillDisable was not specified");
+        this.oomKillDisable = oomKillDisable;
+        return null;
+    }
+
     @Override
     public CreateContainerCmd withPortBindings(PortBinding... portBindings) {
         checkNotNull(portBindings, "portBindings was not specified");
@@ -607,6 +636,7 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
 
     @Override
     public CreateContainerCmdImpl withPortSpecs(String... portSpecs) {
+        checkNotNull(portSpecs, "portSpecs was not specified");
         this.portSpecs = portSpecs;
         return this;
     }
@@ -623,8 +653,15 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
         return this;
     }
 
+    @Override
+    public CreateContainerCmd withReadonlyRootfs(boolean readonlyRootfs) {
+        hostConfig.setReadonlyRootfs(readonlyRootfs);
+        return this;
+    }
+
     @Override
     public CreateContainerCmd withRestartPolicy(RestartPolicy restartPolicy) {
+        checkNotNull(restartPolicy, "restartPolicy was not specified");
         this.hostConfig.setRestartPolicy(restartPolicy);
         return this;
     }
@@ -647,26 +684,37 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
         return this;
     }
 
+    @Override
+    public CreateContainerCmd withUlimits(Ulimit[] ulimits) {
+        checkNotNull(ulimits, "no ulimits was specified");
+        hostConfig.setUlimits(ulimits);
+        return this;
+    }
+
     @Override
     public CreateContainerCmdImpl withUser(String user) {
+        checkNotNull(user, "user was not specified");
         this.user = user;
         return this;
     }
 
     @Override
     public CreateContainerCmdImpl withVolumes(Volume... volumes) {
+        checkNotNull(volumes, "volumes was not specified");
         this.volumes = new Volumes(volumes);
         return this;
     }
 
     @Override
     public CreateContainerCmdImpl withVolumesFrom(VolumesFrom... volumesFrom) {
+        checkNotNull(volumesFrom, "volumesFrom was not specified");
         this.hostConfig.setVolumesFrom(volumesFrom);
         return this;
     }
 
     @Override
     public CreateContainerCmdImpl withWorkingDir(String workingDir) {
+        checkNotNull(workingDir, "workingDir was not specified");
         this.workingDir = workingDir;
         return this;
     }


Test patch:
diff --git a/src/test/java/com/github/dockerjava/core/command/CreateContainerCmdImplTest.java b/src/test/java/com/github/dockerjava/core/command/CreateContainerCmdImplTest.java
index 00322bff..9d682e24 100644
--- a/src/test/java/com/github/dockerjava/core/command/CreateContainerCmdImplTest.java
+++ b/src/test/java/com/github/dockerjava/core/command/CreateContainerCmdImplTest.java
@@ -254,10 +254,8 @@ public class CreateContainerCmdImplTest extends AbstractDockerClientTest {
         LOG.info("Container1 Inspect: {}", inspectContainerResponse1.toString());
         assertThat(inspectContainerResponse1.getState().isRunning(), is(true));
 
-        HostConfig hostConfig = new HostConfig();
-        hostConfig.setLinks(new Link("container1", "container1Link"));
         CreateContainerResponse container2 = dockerClient.createContainerCmd("busybox").withName("container2")
-                .withHostConfig(hostConfig).withCmd("env").exec();
+                .withCmd("env").withLinks(new Link("container1", "container1Link")).exec();
         LOG.info("Created container {}", container2.toString());
         assertThat(container2.getId(), not(isEmptyString()));
 
@@ -324,11 +322,8 @@ public class CreateContainerCmdImplTest extends AbstractDockerClientTest {
 
         String[] extraHosts = { "dockerhost:127.0.0.1", "otherhost:10.0.0.1" };
 
-        HostConfig hostConfig = new HostConfig();
-        hostConfig.setExtraHosts(extraHosts);
-
         CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withName("container")
-                .withHostConfig(hostConfig).exec();
+                .withExtraHosts(extraHosts).exec();
 
         LOG.info("Created container {}", container.toString());
 
@@ -497,11 +492,8 @@ public class CreateContainerCmdImplTest extends AbstractDockerClientTest {
 
         Ulimit[] ulimits = { new Ulimit("nproc", 709, 1026), new Ulimit("nofile", 1024, 4096) };
 
-        HostConfig hostConfig = new HostConfig();
-        hostConfig.setUlimits(ulimits);
-
         CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withName("container")
-                .withHostConfig(hostConfig).exec();
+                .withUlimits(ulimits).exec();
 
         LOG.info("Created container {}", container.toString());