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 371774414..ab4ac9fe8 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.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 static interface Exec extends DockerCmdSyncExec getLabels() { + return labels; } @Override @JsonIgnore - public Map getLabels() { - return labels; + public Link[] getLinks() { + return hostConfig.getLinks(); } @Override @@ -312,6 +307,11 @@ public RestartPolicy getRestartPolicy() { return hostConfig.getRestartPolicy(); } + @Override + public Ulimit[] getUlimits() { + return hostConfig.getUlimits(); + } + @Override public String getUser() { return user; @@ -354,6 +354,11 @@ public boolean isNetworkDisabled() { return networkDisabled; } + @Override + public Boolean isOomKillDisable() { + return oomKillDisable; + } + @Override @JsonIgnore public Boolean isPrivileged() { @@ -366,6 +371,10 @@ public Boolean isPublishAllPorts() { return hostConfig.isPublishAllPorts(); } + public boolean isReadonlyRootfs() { + return hostConfig.isReadonlyRootfs(); + } + @Override public boolean isStdInOnce() { return stdInOnce; @@ -407,133 +416,139 @@ public CreateContainerCmdImpl withAttachStdout(boolean attachStdout) { @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 CreateContainerCmd withLxcConf(LxcConf... lxcConf) { @Override public CreateContainerCmdImpl withMacAddress(String macAddress) { + checkNotNull(macAddress, "macAddress was not specified"); this.macAddress = macAddress; return this; } @@ -584,6 +600,12 @@ public CreateContainerCmdImpl withName(String name) { 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 CreateContainerCmd withNetworkMode(String networkMode) { 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 CreateContainerCmd withPortBindings(Ports portBindings) { @Override public CreateContainerCmdImpl withPortSpecs(String... portSpecs) { + checkNotNull(portSpecs, "portSpecs was not specified"); this.portSpecs = portSpecs; return this; } @@ -623,8 +653,15 @@ public CreateContainerCmd withPublishAllPorts(boolean publishAllPorts) { 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 CreateContainerCmdImpl withTty(boolean tty) { 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; } 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 00322bffa..9d682e248 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 void createContainerWithLink() throws DockerException { 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 void createContainerWithExtraHosts() throws DockerException { 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 void createContainerWithULimits() throws DockerException { 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());