Repository: docker-java/docker-java
Pull request #249 (2015-06-16 21:33:21)

(partial) Update CreateContainer with 1.19 changes
relates to #246  and #229

KostyaSha: So, if i'm implementing newer methods and 1.17 api will be used, how they should like?

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b76a052d..b71f4e92 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,9 +2,6 @@ Change Log
 ===
 Latest SNAPSHOT
 ---
-* [#248](https://github.com/docker-java/docker-java/pull/233) Removed deprecated start options
-* [#247](https://github.com/docker-java/docker-java/pull/247) Add Domainname attribute on create command
-* [#245](https://github.com/docker-java/docker-java/pull/245) Added ReadonlyRootfs option
 * [#233](https://github.com/docker-java/docker-java/pull/233) Labels are array of Strings (fixes #232) 
 * [#189](https://github.com/docker-java/docker-java/pull/189) Add docker stats support  
 
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 3b558b6d..136b5aec 100644
--- a/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java
+++ b/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java
@@ -41,6 +41,26 @@ public interface CreateContainerCmd extends DockerCmd<CreateContainerResponse> {
 
     public int getCpuShares();
 
+    /**
+     * @since 1.19
+     */
+    public Integer getCpuPeriod();
+
+    /**
+     * @since 1.19
+     */
+    public String getCpusetMems();
+
+    /**
+     * @since 1.19
+     */
+    public Integer getBlkioWeight();
+
+    /**
+     * @since 1.19
+     */
+    public Boolean isOomKillDisable();
+
     public Device[] getDevices();
 
     public String[] getDns();
@@ -137,6 +157,26 @@ public interface CreateContainerCmd extends DockerCmd<CreateContainerResponse> {
 
     public CreateContainerCmd withCpuShares(int cpuShares);
 
+    /**
+     * @since 1.19
+     */
+    public CreateContainerCmd withCpuPeriod(Integer cpuPeriod);
+
+    /**
+     * @since 1.19
+     */
+    public CreateContainerCmd withCpusetMems(String cpusetMems);
+
+    /**
+     * @since 1.19
+     */
+    public CreateContainerCmd withBlkioWeight(Integer blkioWeight);
+
+    /**
+     * @since 1.19
+     */
+    public CreateContainerCmd withOomKillDisable(Boolean oomKillDisable);
+
     /**
      * Add host devices to the container
      */
diff --git a/src/main/java/com/github/dockerjava/api/command/StartContainerCmd.java b/src/main/java/com/github/dockerjava/api/command/StartContainerCmd.java
index 2195e1ec..aeddfd0b 100644
--- a/src/main/java/com/github/dockerjava/api/command/StartContainerCmd.java
+++ b/src/main/java/com/github/dockerjava/api/command/StartContainerCmd.java
@@ -2,26 +2,170 @@ package com.github.dockerjava.api.command;
 
 import com.github.dockerjava.api.NotFoundException;
 import com.github.dockerjava.api.NotModifiedException;
+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.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.VolumesFrom;
 
 /**
  * Start a container.
- *
+ * 
+ * TODO: Almost all methods are deprecated as they have corresponding siblings in {@link CreateContainerCmd} now.
  */
 public interface StartContainerCmd extends DockerCmd<Void> {
 
-    public static interface Exec extends DockerCmdExec<StartContainerCmd, Void> {
-    }
+	public static interface Exec extends DockerCmdExec<StartContainerCmd, Void> {
+	}
 
-    String getContainerId();
+	/**
+	 * @throws NotFoundException
+	 *             No such container
+	 * @throws NotModifiedException
+	 *             Container already started
+	 */
+	@Override
+	public Void exec() throws NotFoundException, NotModifiedException;
 
-    StartContainerCmd withContainerId(String containerId);
+	public Bind[] getBinds();
+
+	public Capability[] getCapAdd();
+
+	public Capability[] getCapDrop();
+
+	public String getContainerId();
+
+	public Device[] getDevices();
+
+	public String[] getDns();
+
+	public String[] getDnsSearch();
+
+	public String[] getExtraHosts();
+
+	public Link[] getLinks();
+
+	public LxcConf[] getLxcConf();
+
+	public String getNetworkMode();
+
+	public Ports getPortBindings();
+
+	public RestartPolicy getRestartPolicy();
+
+	public VolumesFrom[] getVolumesFrom();
+
+	public Boolean isPrivileged();
+
+	public Boolean isPublishAllPorts();
+
+	@Deprecated
+	public StartContainerCmd withBinds(Bind... binds);
+
+	/**
+	 * Add linux <a
+	 * href="http://man7.org/linux/man-pages/man7/capabilities.7.html">kernel
+	 * capability</a> to the container. For example: adding {@link Capability#MKNOD}
+	 * allows the container to create special files using the 'mknod' command.
+	 */
+	@Deprecated
+	public StartContainerCmd withCapAdd(Capability... capAdd);
+
+	/**
+	 * Drop linux <a
+	 * href="http://man7.org/linux/man-pages/man7/capabilities.7.html">kernel
+	 * capability</a> from the container. For example: dropping {@link Capability#CHOWN}
+	 * prevents the container from changing the owner of any files.
+	 */
+	@Deprecated
+	public StartContainerCmd withCapDrop(Capability... capDrop);
+
+	@Deprecated
+	public StartContainerCmd withContainerId(String containerId);
+
+	/**
+	 * Add host devices to the container
+	 */
+	@Deprecated
+	public StartContainerCmd withDevices(Device... devices);
+
+	/**
+	 * Set custom DNS servers
+	 */
+	@Deprecated
+	public StartContainerCmd withDns(String... dns);
+
+	/**
+	 * Set custom DNS search domains
+	 */
+	@Deprecated
+	public StartContainerCmd withDnsSearch(String... dnsSearch);
+
+	/**
+	 * Add hostnames to /etc/hosts in the container
+	 */
+	@Deprecated
+	public StartContainerCmd withExtraHosts(String... extraHosts);
+
+	/**
+	 * Add link to another container.
+	 */
+	@Deprecated
+	public StartContainerCmd withLinks(Link... links);
+
+	@Deprecated
+	public StartContainerCmd withLxcConf(LxcConf... lxcConf);
+
+	/**
+	 * Set the Network mode for the container
+	 * <ul>
+	 * <li>'bridge': creates a new network stack for the container on the docker
+	 * bridge</li>
+	 * <li>'none': no networking for this container</li>
+	 * <li>'container:<name|id>': reuses another container network stack</li>
+	 * <li>'host': use the host network stack inside the container. Note: the
+	 * host mode gives the container full access to local system services such
+	 * as D-bus and is therefore considered insecure.</li>
+	 * </ul>
+	 */
+	@Deprecated
+	public StartContainerCmd withNetworkMode(String networkMode);
+
+	/**
+	 * Add one or more {@link PortBinding}s.
+	 * This corresponds to the <code>--publish</code> (<code>-p</code>)
+	 * option of the <code>docker run</code> CLI command.
+	 */
+	@Deprecated
+	public StartContainerCmd withPortBindings(PortBinding... portBindings);
+
+	/**
+	 * Add the port bindings that are contained in the given {@link Ports}
+	 * object.
+	 * 
+	 * @see #withPortBindings(PortBinding...)
+	 */
+	@Deprecated
+	public StartContainerCmd withPortBindings(Ports portBindings);
+
+	@Deprecated
+	public StartContainerCmd withPrivileged(Boolean privileged);
+
+	@Deprecated
+	public StartContainerCmd withPublishAllPorts(Boolean publishAllPorts);
+
+	/**
+	 * Set custom {@link RestartPolicy} for the container. Defaults to
+	 * {@link RestartPolicy#noRestart()}
+	 */
+	@Deprecated
+	public StartContainerCmd withRestartPolicy(RestartPolicy restartPolicy);
+
+	@Deprecated
+	public StartContainerCmd withVolumesFrom(VolumesFrom... volumesFrom);
 
-    /**
-     * @throws NotFoundException
-     *             No such container
-     * @throws NotModifiedException
-     *             Container already started
-     */
-    @Override
-    public Void exec() throws NotFoundException, NotModifiedException;
 }
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 cc082b61..eb57dfff 100644
--- a/src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java
+++ b/src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java
@@ -53,6 +53,9 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
     @JsonProperty("CpuShares")
     private int cpuShares = 0;
 
+    @JsonProperty("CpuPeriod")
+    private Integer cpuPeriod;
+
     @JsonProperty("Cpuset")
     private String cpuset;
 
@@ -107,6 +110,15 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
     @JsonProperty("HostConfig")
     private HostConfig hostConfig = new HostConfig();
 
+    @JsonProperty("CpusetMems")
+    private String cpusetMems;
+
+    @JsonProperty("BlkioWeight")
+    private Integer blkioWeight;
+
+    @JsonProperty("OomKillDisable")
+    private Boolean oomKillDisable;
+
     public CreateContainerCmdImpl(CreateContainerCmd.Exec exec, String image) {
         super(exec);
         checkNotNull(image, "image was not specified");
@@ -155,6 +167,26 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
         return cpuShares;
     }
 
+    @Override
+    public Integer getCpuPeriod() {
+        return cpuPeriod;
+    }
+
+    @Override
+    public String getCpusetMems() {
+        return cpusetMems;
+    }
+
+    @Override
+    public Integer getBlkioWeight() {
+        return blkioWeight;
+    }
+
+    @Override
+    public Boolean isOomKillDisable() {
+        return oomKillDisable;
+    }
+
     @Override
     @JsonIgnore
     public Device[] getDevices() {
@@ -398,6 +430,30 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
         return this;
     }
 
+    @Override
+    public CreateContainerCmd withCpuPeriod(Integer cpuPeriod) {
+        this.cpuPeriod = cpuPeriod;
+        return this;
+    }
+
+    @Override
+    public CreateContainerCmd withCpusetMems(String cpusetMems) {
+        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;
+    }
+
     @Override
     public CreateContainerCmd withDevices(Device... devices) {
         this.hostConfig.setDevices(devices);
diff --git a/src/main/java/com/github/dockerjava/core/command/StartContainerCmdImpl.java b/src/main/java/com/github/dockerjava/core/command/StartContainerCmdImpl.java
index 6fe60734..27fca12f 100644
--- a/src/main/java/com/github/dockerjava/core/command/StartContainerCmdImpl.java
+++ b/src/main/java/com/github/dockerjava/core/command/StartContainerCmdImpl.java
@@ -7,9 +7,22 @@ import org.apache.commons.lang.builder.ToStringBuilder;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
 import com.github.dockerjava.api.NotFoundException;
 import com.github.dockerjava.api.NotModifiedException;
 import com.github.dockerjava.api.command.StartContainerCmd;
+import com.github.dockerjava.api.model.Bind;
+import com.github.dockerjava.api.model.Binds;
+import com.github.dockerjava.api.model.Capability;
+import com.github.dockerjava.api.model.Device;
+import com.github.dockerjava.api.model.Link;
+import com.github.dockerjava.api.model.Links;
+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.VolumesFrom;
+
 
 /**
  * Start a container
@@ -17,39 +30,276 @@ import com.github.dockerjava.api.command.StartContainerCmd;
 @JsonInclude(NON_EMPTY)
 public class StartContainerCmdImpl extends AbstrDockerCmd<StartContainerCmd, Void> implements StartContainerCmd {
 
-    @JsonIgnore
-    private String containerId;
+	@JsonIgnore
+	private String containerId;
 
-    public StartContainerCmdImpl(StartContainerCmd.Exec exec, String containerId) {
-        super(exec);
-        withContainerId(containerId);
-    }
+	@JsonProperty("Binds")
+	private Binds binds;
+
+	@JsonProperty("Links")
+	private Links links;
+
+	@JsonProperty("LxcConf")
+	private LxcConf[] lxcConf;
+
+	@JsonProperty("PortBindings")
+	private Ports portBindings;
+
+	@JsonProperty("PublishAllPorts")
+	private Boolean publishAllPorts;
+
+	@JsonProperty("Privileged")
+	private Boolean privileged;
+
+	@JsonProperty("Dns")
+	private String[] dns;
+	
+	@JsonProperty("DnsSearch")
+	private String[] dnsSearch;
+
+	@JsonProperty("VolumesFrom")
+	private VolumesFrom[] volumesFrom;
+	
+	@JsonProperty("NetworkMode")          
+    private String networkMode;
+	
+	@JsonProperty("Devices")
+	private Device[] devices;
+	
+	@JsonProperty("ExtraHosts")
+	private String[] extraHosts;
+	
+	@JsonProperty("RestartPolicy")
+	private RestartPolicy restartPolicy;
+	
+	@JsonProperty("CapAdd")
+	private Capability[] capAdd;
+	
+	@JsonProperty("CapDrop")
+	private Capability[] capDrop;
+	
+	public StartContainerCmdImpl(StartContainerCmd.Exec exec, String containerId) {
+		super(exec);
+		withContainerId(containerId);
+	}
+
+	@Override
+	@JsonIgnore
+	public Bind[] getBinds() {
+		return (binds == null) ? new Bind[0] : binds.getBinds();
+	}
+
+	@Override
+	@JsonIgnore
+	public Link[] getLinks() {
+		return (links == null) ? new Link[0] : links.getLinks();
+	}
 
+	@Override
+	public LxcConf[] getLxcConf() {
+		return lxcConf;
+	}
+
+	@Override
+	public Ports getPortBindings() {
+		return portBindings;
+	}
+
+	@Override
+	public Boolean isPublishAllPorts() {
+		return publishAllPorts;
+	}
+
+	@Override
+	public Boolean isPrivileged() {
+		return privileged;
+	}
+
+	@Override
+	public String[] getDns() {
+		return dns;
+	}
+	
+	@Override
+	public String[] getDnsSearch() {
+		return dnsSearch;
+	}
+
+	@Override
+	public VolumesFrom[] getVolumesFrom() {
+		return volumesFrom;
+	}
+
+	@Override
+	public String getContainerId() {
+		return containerId;
+	}
+	   
     @Override
-    public StartContainerCmd withContainerId(String containerId) {
-        checkNotNull(containerId, "containerId was not specified");
-        this.containerId = containerId;
-        return this;
+	public String getNetworkMode() {        
+        return networkMode;
     }
-
+    
+    @Override
+    public Device[] getDevices() {
+		return devices;
+	}
+    
     @Override
-    public String getContainerId() {
-        return containerId;
+    public String[] getExtraHosts() {
+		return extraHosts;
+	}
+    
+    @Override
+    public RestartPolicy getRestartPolicy() {
+    	return restartPolicy;
     }
-
+    
     @Override
-    public String toString() {
-        return ToStringBuilder.reflectionToString(this).toString();
+    public Capability[] getCapAdd() {
+    	return capAdd;
+    }
+    
+    @Override
+    public Capability[] getCapDrop() {
+    	return capDrop;
+    }
+
+	@Override
+	@JsonIgnore
+	public StartContainerCmd withBinds(Bind... binds) {
+		checkNotNull(binds, "binds was not specified");
+		this.binds = new Binds(binds);
+		return this;
+	}
+
+	@Override
+	@JsonIgnore
+	public StartContainerCmd withLinks(Link... links) {
+		checkNotNull(links, "links was not specified");
+		this.links = new Links(links);
+		return this;
+	}
+
+	@Override
+	public StartContainerCmd withLxcConf(LxcConf... lxcConf) {
+		checkNotNull(lxcConf, "lxcConf was not specified");
+		this.lxcConf = lxcConf;
+		return this;
+	}
+
+	@Override
+	public StartContainerCmd withPortBindings(Ports portBindings) {
+		checkNotNull(portBindings,
+				"portBindings was not specified");
+		this.portBindings = portBindings;
+		return this;
+	}
+
+	@Override
+	public StartContainerCmd withPortBindings(PortBinding... portBindings) {
+		checkNotNull(portBindings, "portBindings was not specified");
+		if (this.portBindings == null) {
+			this.portBindings = new Ports();
+		}
+		this.portBindings.add(portBindings);
+		return this;
+	}
+
+	@Override
+	public StartContainerCmd withPrivileged(Boolean privileged) {
+		this.privileged = privileged;
+		return this;
+	}
+
+	@Override
+	public StartContainerCmd withPublishAllPorts(Boolean publishAllPorts) {
+		this.publishAllPorts = publishAllPorts;
+		return this;
+	}
+
+	@Override
+	public StartContainerCmd withDns(String... dns) {
+		checkNotNull(dns, "dns was not specified");
+		this.dns = dns;
+		return this;
+	}
+	
+	@Override
+	public StartContainerCmd withDnsSearch(String... dnsSearch) {
+		checkNotNull(dnsSearch, "dnsSearch was not specified");
+		this.dnsSearch = dnsSearch;
+		return this;
+	}
+
+	@Override
+	public StartContainerCmd withVolumesFrom(VolumesFrom... volumesFrom) {
+		checkNotNull(volumesFrom, "volumesFrom was not specified");
+		this.volumesFrom = volumesFrom;
+		return this;
+	}
+
+	@Override
+	public StartContainerCmd withContainerId(String containerId) {
+	    checkNotNull(containerId, "containerId was not specified");
+		this.containerId = containerId;
+		return this;
     }
 
-    /**
-     * @throws NotFoundException
-     *             No such container
-     * @throws NotModifiedException
-     *             Container already started
-     */
     @Override
-    public Void exec() throws NotFoundException, NotModifiedException {
-        return super.exec();
+	public StartContainerCmd withNetworkMode(String networkMode) {
+        checkNotNull(networkMode, "networkMode was not specified");
+        this.networkMode = networkMode;
+        return this;
     }
+    
+    @Override
+	public StartContainerCmd withDevices(Device... devices) {
+		checkNotNull(devices, "devices was not specified");
+		this.devices = devices;
+		return this;
+	}
+
+    @Override
+	public StartContainerCmd withExtraHosts(String... extraHosts) {
+		checkNotNull(extraHosts, "extraHosts was not specified");
+		this.extraHosts = extraHosts;
+		return this;
+	}
+    
+    
+    @Override
+   	public StartContainerCmd withRestartPolicy(RestartPolicy restartPolicy) {
+   		checkNotNull(restartPolicy, "restartPolicy was not specified");
+   		this.restartPolicy = restartPolicy;
+   		return this;
+   	}
+    
+    @Override
+	public StartContainerCmd withCapAdd(Capability... capAdd) {
+		checkNotNull(capAdd, "capAdd was not specified");
+		this.capAdd = capAdd;
+		return this;
+	}
+    
+    @Override
+	public StartContainerCmd withCapDrop(Capability... capDrop) {
+		checkNotNull(capDrop, "capDrop was not specified");
+		this.capDrop = capDrop;
+		return this;
+	}
+
+	@Override
+	public String toString() {
+		return ToStringBuilder.reflectionToString(this).toString();
+	}
+	
+	/**
+	 * @throws NotFoundException No such container
+	 * @throws NotModifiedException Container already started
+	 */
+	@Override
+	public Void exec() throws NotFoundException, NotModifiedException {
+		return super.exec();
+	}
 }


Test patch:
diff --git a/src/test/java/com/github/dockerjava/core/command/StartContainerCmdImplTest.java b/src/test/java/com/github/dockerjava/core/command/StartContainerCmdImplTest.java
index d690f4e1..64083991 100644
--- a/src/test/java/com/github/dockerjava/core/command/StartContainerCmdImplTest.java
+++ b/src/test/java/com/github/dockerjava/core/command/StartContainerCmdImplTest.java
@@ -1,8 +1,8 @@
 package com.github.dockerjava.core.command;
 
 import static com.github.dockerjava.api.model.AccessMode.ro;
-import static com.github.dockerjava.api.model.Capability.MKNOD;
-import static com.github.dockerjava.api.model.Capability.NET_ADMIN;
+import static com.github.dockerjava.api.model.Capability.*;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.contains;
 import static org.hamcrest.Matchers.equalTo;
@@ -13,15 +13,7 @@ import static org.hamcrest.Matchers.notNullValue;
 import static org.hamcrest.Matchers.startsWith;
 
 import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.UUID;
-
-import org.testng.ITestResult;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
+import java.util.*;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.github.dockerjava.api.DockerException;
@@ -30,523 +22,633 @@ import com.github.dockerjava.api.NotFoundException;
 import com.github.dockerjava.api.command.CreateContainerResponse;
 import com.github.dockerjava.api.command.InspectContainerResponse;
 import com.github.dockerjava.api.command.StartContainerCmd;
-import com.github.dockerjava.api.model.AccessMode;
-import com.github.dockerjava.api.model.Bind;
-import com.github.dockerjava.api.model.Device;
-import com.github.dockerjava.api.model.ExposedPort;
-import com.github.dockerjava.api.model.Link;
-import com.github.dockerjava.api.model.Ports;
-import com.github.dockerjava.api.model.RestartPolicy;
-import com.github.dockerjava.api.model.Volume;
-import com.github.dockerjava.api.model.VolumeRW;
-import com.github.dockerjava.api.model.VolumesFrom;
+import com.github.dockerjava.api.model.*;
+
+import org.testng.ITestResult;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
 import com.github.dockerjava.client.AbstractDockerClientTest;
 
 @Test(groups = "integration")
 public class StartContainerCmdImplTest extends AbstractDockerClientTest {
 
-    @BeforeTest
-    public void beforeTest() throws DockerException {
-        super.beforeTest();
-    }
-
-    @AfterTest
-    public void afterTest() {
-        super.afterTest();
-    }
-
-    @BeforeMethod
-    public void beforeMethod(Method method) {
-        super.beforeMethod(method);
-    }
-
-    @AfterMethod
-    public void afterMethod(ITestResult result) {
-        super.afterMethod(result);
-    }
-
-    @Test
-    public void startContainerWithVolumes() throws DockerException {
-
-        // see http://docs.docker.io/use/working_with_volumes/
-        Volume volume1 = new Volume("/opt/webapp1");
-
-        Volume volume2 = new Volume("/opt/webapp2");
-
-        CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withVolumes(volume1, volume2)
-                .withCmd("true").withBinds(new Bind("/src/webapp1", volume1, ro), new Bind("/src/webapp2", volume2))
-                .exec();
+	@BeforeTest
+	public void beforeTest() throws DockerException {
+		super.beforeTest();
+	}
 
-        LOG.info("Created container {}", container.toString());
+	@AfterTest
+	public void afterTest() {
+		super.afterTest();
+	}
 
-        assertThat(container.getId(), not(isEmptyString()));
+	@BeforeMethod
+	public void beforeMethod(Method method) {
+		super.beforeMethod(method);
+	}
 
-        InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
+	@AfterMethod
+	public void afterMethod(ITestResult result) {
+		super.afterMethod(result);
+	}
 
-        assertThat(inspectContainerResponse.getConfig().getVolumes().keySet(), contains("/opt/webapp1", "/opt/webapp2"));
+	@Test
+	public void startContainerWithVolumes() throws DockerException {
 
-        dockerClient.startContainerCmd(container.getId()).exec();
+		// see http://docs.docker.io/use/working_with_volumes/
+		Volume volume1 = new Volume("/opt/webapp1");
 
-        dockerClient.waitContainerCmd(container.getId()).exec();
+		Volume volume2 = new Volume("/opt/webapp2");
 
-        inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
+		CreateContainerResponse container = dockerClient
+				.createContainerCmd("busybox").withVolumes(volume1, volume2)
+				.withCmd("true").exec();
 
-        assertContainerHasVolumes(inspectContainerResponse, volume1, volume2);
+		LOG.info("Created container {}", container.toString());
 
-        assertThat(Arrays.asList(inspectContainerResponse.getVolumesRW()),
-                contains(new VolumeRW(volume1, AccessMode.ro), new VolumeRW(volume2)));
+		assertThat(container.getId(), not(isEmptyString()));
 
-    }
+		InspectContainerResponse inspectContainerResponse = dockerClient
+				.inspectContainerCmd(container.getId()).exec();
 
-    @Test
-    public void startContainerWithVolumesFrom() throws DockerException {
+		assertThat(inspectContainerResponse.getConfig().getVolumes().keySet(),
+				contains("/opt/webapp1", "/opt/webapp2"));
 
-        Volume volume1 = new Volume("/opt/webapp1");
-        Volume volume2 = new Volume("/opt/webapp2");
+		dockerClient
+				.startContainerCmd(container.getId())
+				.withBinds(new Bind("/src/webapp1", volume1, ro),
+						new Bind("/src/webapp2", volume2)).exec();
 
-        String container1Name = UUID.randomUUID().toString();
+		dockerClient.waitContainerCmd(container.getId()).exec();
 
-        CreateContainerResponse container1 = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999")
-                .withName(container1Name)
-                .withBinds(new Bind("/src/webapp1", volume1), new Bind("/src/webapp2", volume2)).exec();
-        LOG.info("Created container1 {}", container1.toString());
+		inspectContainerResponse = dockerClient.inspectContainerCmd(
+				container.getId()).exec();
 
-        dockerClient.startContainerCmd(container1.getId()).exec();
-        LOG.info("Started container1 {}", container1.toString());
+		assertContainerHasVolumes(inspectContainerResponse, volume1, volume2);
 
-        InspectContainerResponse inspectContainerResponse1 = dockerClient.inspectContainerCmd(container1.getId())
-                .exec();
+		assertThat(
+				Arrays.asList(inspectContainerResponse.getVolumesRW()),
+				contains(new VolumeRW(volume1, AccessMode.ro), new VolumeRW(
+						volume2)));
 
-        assertContainerHasVolumes(inspectContainerResponse1, volume1, volume2);
+	}
 
-        CreateContainerResponse container2 = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999")
-                .withVolumesFrom(new VolumesFrom(container1Name)).exec();
-        LOG.info("Created container2 {}", container2.toString());
+	@Test
+	public void startContainerWithVolumesFrom() throws DockerException {
 
-        dockerClient.startContainerCmd(container2.getId()).exec();
-        LOG.info("Started container2 {}", container2.toString());
+		Volume volume1 = new Volume("/opt/webapp1");
+		Volume volume2 = new Volume("/opt/webapp2");
 
-        InspectContainerResponse inspectContainerResponse2 = dockerClient.inspectContainerCmd(container2.getId())
-                .exec();
+		String container1Name = UUID.randomUUID().toString();
 
-        assertContainerHasVolumes(inspectContainerResponse2, volume1, volume2);
-    }
+		CreateContainerResponse container1 = dockerClient
+				.createContainerCmd("busybox").withCmd("sleep", "9999")
+				.withName(container1Name).exec();
+		LOG.info("Created container1 {}", container1.toString());
 
-    @Test
-    public void startContainerWithDns() throws DockerException {
+		dockerClient
+				.startContainerCmd(container1.getId())
+				.withBinds(new Bind("/src/webapp1", volume1),
+						new Bind("/src/webapp2", volume2)).exec();
+		LOG.info("Started container1 {}", container1.toString());
 
-        String aDnsServer = "8.8.8.8";
-        String anotherDnsServer = "8.8.4.4";
+		InspectContainerResponse inspectContainerResponse1 = dockerClient
+				.inspectContainerCmd(container1.getId()).exec();
 
-        CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("true")
-                .withDns(aDnsServer, anotherDnsServer).exec();
+		assertContainerHasVolumes(inspectContainerResponse1, volume1, volume2);
 
-        LOG.info("Created container {}", container.toString());
+		CreateContainerResponse container2 = dockerClient
+				.createContainerCmd("busybox").withCmd("sleep", "9999").exec();
+		LOG.info("Created container2 {}", container2.toString());
 
-        assertThat(container.getId(), not(isEmptyString()));
+		dockerClient.startContainerCmd(container2.getId())
+				.withVolumesFrom(new VolumesFrom(container1Name)).exec();
+		LOG.info("Started container2 {}", container2.toString());
 
-        dockerClient.startContainerCmd(container.getId()).exec();
+		InspectContainerResponse inspectContainerResponse2 = dockerClient
+				.inspectContainerCmd(container2.getId()).exec();
 
-        InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
+		assertContainerHasVolumes(inspectContainerResponse2, volume1, volume2);
+	}
 
-        assertThat(Arrays.asList(inspectContainerResponse.getHostConfig().getDns()),
-                contains(aDnsServer, anotherDnsServer));
-    }
+	@Test
+	public void startContainerWithDns() throws DockerException {
 
-    @Test
-    public void startContainerWithDnsSearch() throws DockerException {
+		String aDnsServer = "8.8.8.8";
+		String anotherDnsServer = "8.8.4.4";
 
-        String dnsSearch = "example.com";
+		CreateContainerResponse container = dockerClient
+				.createContainerCmd("busybox").withCmd("true").exec();
 
-        CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("true")
-                .withDnsSearch(dnsSearch).exec();
+		LOG.info("Created container {}", container.toString());
 
-        LOG.info("Created container {}", container.toString());
+		assertThat(container.getId(), not(isEmptyString()));
 
-        assertThat(container.getId(), not(isEmptyString()));
+		dockerClient.startContainerCmd(container.getId())
+				.withDns(aDnsServer, anotherDnsServer).exec();
 
-        InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
+		InspectContainerResponse inspectContainerResponse = dockerClient
+				.inspectContainerCmd(container.getId()).exec();
 
-        dockerClient.startContainerCmd(container.getId()).exec();
+		assertThat(Arrays.asList(inspectContainerResponse.getHostConfig()
+				.getDns()), contains(aDnsServer, anotherDnsServer));
+	}
 
-        inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
+	@Test
+	public void startContainerWithDnsSearch() throws DockerException {
 
-        assertThat(Arrays.asList(inspectContainerResponse.getHostConfig().getDnsSearch()), contains(dnsSearch));
-    }
+		String dnsSearch = "example.com";
 
-    @Test
-    public void startContainerWithPortBindings() throws DockerException {
+		CreateContainerResponse container = dockerClient
+				.createContainerCmd("busybox").withCmd("true").exec();
 
-        ExposedPort tcp22 = ExposedPort.tcp(22);
-        ExposedPort tcp23 = ExposedPort.tcp(23);
+		LOG.info("Created container {}", container.toString());
 
-        Ports portBindings = new Ports();
-        portBindings.bind(tcp22, Ports.Binding(11022));
-        portBindings.bind(tcp23, Ports.Binding(11023));
-        portBindings.bind(tcp23, Ports.Binding(11024));
+		assertThat(container.getId(), not(isEmptyString()));
 
-        CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("true")
-                .withExposedPorts(tcp22, tcp23).withPortBindings(portBindings).exec();
+		InspectContainerResponse inspectContainerResponse = dockerClient
+				.inspectContainerCmd(container.getId()).exec();
 
-        LOG.info("Created container {}", container.toString());
+		dockerClient.startContainerCmd(container.getId())
+				.withDnsSearch(dnsSearch).exec();
 
-        assertThat(container.getId(), not(isEmptyString()));
+		inspectContainerResponse = dockerClient.inspectContainerCmd(
+				container.getId()).exec();
 
-        InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
+		assertThat(Arrays.asList(inspectContainerResponse.getHostConfig()
+				.getDnsSearch()), contains(dnsSearch));
+	}
 
-        dockerClient.startContainerCmd(container.getId()).exec();
+	@Test
+	public void startContainerWithPortBindings() throws DockerException {
 
-        inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
+		ExposedPort tcp22 = ExposedPort.tcp(22);
+		ExposedPort tcp23 = ExposedPort.tcp(23);
 
-        assertThat(Arrays.asList(inspectContainerResponse.getConfig().getExposedPorts()), contains(tcp22, tcp23));
+		CreateContainerResponse container = dockerClient
+				.createContainerCmd("busybox").withCmd("true")
+				.withExposedPorts(tcp22, tcp23).exec();
 
-        assertThat(inspectContainerResponse.getHostConfig().getPortBindings().getBindings().get(tcp22)[0],
-                is(equalTo(Ports.Binding(11022))));
+		LOG.info("Created container {}", container.toString());
 
-        assertThat(inspectContainerResponse.getHostConfig().getPortBindings().getBindings().get(tcp23)[0],
-                is(equalTo(Ports.Binding(11023))));
+		assertThat(container.getId(), not(isEmptyString()));
 
-        assertThat(inspectContainerResponse.getHostConfig().getPortBindings().getBindings().get(tcp23)[1],
-                is(equalTo(Ports.Binding(11024))));
+		InspectContainerResponse inspectContainerResponse = dockerClient
+				.inspectContainerCmd(container.getId()).exec();
 
-    }
+		Ports portBindings = new Ports();
+		portBindings.bind(tcp22, Ports.Binding(11022));
+		portBindings.bind(tcp23, Ports.Binding(11023));
+		portBindings.bind(tcp23, Ports.Binding(11024));
 
-    @Test
-    public void startContainerWithRandomPortBindings() throws DockerException {
+		dockerClient.startContainerCmd(container.getId())
+				.withPortBindings(portBindings).exec();
 
-        ExposedPort tcp22 = ExposedPort.tcp(22);
-        ExposedPort tcp23 = ExposedPort.tcp(23);
+		inspectContainerResponse = dockerClient.inspectContainerCmd(
+				container.getId()).exec();
 
-        Ports portBindings = new Ports();
-        portBindings.bind(tcp22, Ports.Binding(null));
-        portBindings.bind(tcp23, Ports.Binding(null));
+		assertThat(Arrays.asList(inspectContainerResponse.getConfig()
+				.getExposedPorts()), contains(tcp22, tcp23));
 
-        CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999")
-                .withExposedPorts(tcp22, tcp23).withPortBindings(portBindings).withPublishAllPorts(true).exec();
+		assertThat(inspectContainerResponse.getHostConfig().getPortBindings()
+				.getBindings().get(tcp22)[0], is(equalTo(Ports.Binding(11022))));
 
-        LOG.info("Created container {}", container.toString());
+		assertThat(inspectContainerResponse.getHostConfig().getPortBindings()
+				.getBindings().get(tcp23)[0], is(equalTo(Ports.Binding(11023))));
 
-        assertThat(container.getId(), not(isEmptyString()));
+		assertThat(inspectContainerResponse.getHostConfig().getPortBindings()
+				.getBindings().get(tcp23)[1], is(equalTo(Ports.Binding(11024))));
 
-        dockerClient.startContainerCmd(container.getId()).exec();
+	}
 
-        InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
+	@Test
+	public void startContainerWithRandomPortBindings() throws DockerException {
 
-        assertThat(Arrays.asList(inspectContainerResponse.getConfig().getExposedPorts()), contains(tcp22, tcp23));
+		ExposedPort tcp22 = ExposedPort.tcp(22);
+		ExposedPort tcp23 = ExposedPort.tcp(23);
 
-        assertThat(inspectContainerResponse.getNetworkSettings().getPorts().getBindings().get(tcp22)[0].getHostPort(),
-                is(not(equalTo(tcp22.getPort()))));
+		Ports portBindings = new Ports();
+		portBindings.bind(tcp22, Ports.Binding(null));
+		portBindings.bind(tcp23, Ports.Binding(null));
 
-        assertThat(inspectContainerResponse.getNetworkSettings().getPorts().getBindings().get(tcp23)[0].getHostPort(),
-                is(not(equalTo(tcp23.getPort()))));
+		CreateContainerResponse container = dockerClient
+				.createContainerCmd("busybox").withCmd("sleep", "9999")
+				.withExposedPorts(tcp22, tcp23).withPortBindings(portBindings)
+				.withPublishAllPorts(true).exec();
 
-    }
+		LOG.info("Created container {}", container.toString());
 
-    @Test
-    public void startContainerWithConflictingPortBindings() throws DockerException {
+		assertThat(container.getId(), not(isEmptyString()));
 
-        ExposedPort tcp22 = ExposedPort.tcp(22);
-        ExposedPort tcp23 = ExposedPort.tcp(23);
+		dockerClient.startContainerCmd(container.getId()).exec();
 
-        Ports portBindings = new Ports();
-        portBindings.bind(tcp22, Ports.Binding(11022));
-        portBindings.bind(tcp23, Ports.Binding(11022));
+		InspectContainerResponse inspectContainerResponse = dockerClient
+				.inspectContainerCmd(container.getId()).exec();
 
-        CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("true")
-                .withExposedPorts(tcp22, tcp23).withPortBindings(portBindings).exec();
+		assertThat(Arrays.asList(inspectContainerResponse.getConfig()
+				.getExposedPorts()), contains(tcp22, tcp23));
 
-        LOG.info("Created container {}", container.toString());
+		assertThat(inspectContainerResponse.getNetworkSettings().getPorts()
+				.getBindings().get(tcp22)[0].getHostPort(), is(not(equalTo(tcp22.getPort()))));
 
-        assertThat(container.getId(), not(isEmptyString()));
+		assertThat(inspectContainerResponse.getNetworkSettings().getPorts()
+				.getBindings().get(tcp23)[0].getHostPort(), is(not(equalTo(tcp23.getPort()))));
 
-        try {
-            dockerClient.startContainerCmd(container.getId()).exec();
-            fail("expected InternalServerErrorException");
-        } catch (InternalServerErrorException e) {
+	}
 
-        }
+	@Test
+	public void startContainerWithConflictingPortBindings()
+			throws DockerException {
 
-    }
+		ExposedPort tcp22 = ExposedPort.tcp(22);
+		ExposedPort tcp23 = ExposedPort.tcp(23);
 
-    @Test
-    public void startContainerWithLinkingDeprecated() throws DockerException {
+		CreateContainerResponse container = dockerClient
+				.createContainerCmd("busybox").withCmd("true")
+				.withExposedPorts(tcp22, tcp23).exec();
 
-        CreateContainerResponse container1 = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999")
-                .withName("container1").exec();
+		LOG.info("Created container {}", container.toString());
 
-        LOG.info("Created container1 {}", container1.toString());
-        assertThat(container1.getId(), not(isEmptyString()));
+		assertThat(container.getId(), not(isEmptyString()));
 
-        dockerClient.startContainerCmd(container1.getId()).exec();
+		Ports portBindings = new Ports();
+		portBindings.bind(tcp22, Ports.Binding(11022));
+		portBindings.bind(tcp23, Ports.Binding(11022));
 
-        InspectContainerResponse inspectContainerResponse1 = dockerClient.inspectContainerCmd(container1.getId())
-                .exec();
-        LOG.info("Container1 Inspect: {}", inspectContainerResponse1.toString());
+		try {
+			dockerClient.startContainerCmd(container.getId())
+					.withPortBindings(portBindings).exec();
+			fail("expected InternalServerErrorException");
+		} catch (InternalServerErrorException e) {
 
-        assertThat(inspectContainerResponse1.getConfig(), is(notNullValue()));
-        assertThat(inspectContainerResponse1.getId(), not(isEmptyString()));
-        assertThat(inspectContainerResponse1.getId(), startsWith(container1.getId()));
-        assertThat(inspectContainerResponse1.getName(), equalTo("/container1"));
-        assertThat(inspectContainerResponse1.getImageId(), not(isEmptyString()));
-        assertThat(inspectContainerResponse1.getState(), is(notNullValue()));
-        assertThat(inspectContainerResponse1.getState().isRunning(), is(true));
+		}
 
-        if (!inspectContainerResponse1.getState().isRunning()) {
-            assertThat(inspectContainerResponse1.getState().getExitCode(), is(equalTo(0)));
-        }
+	}
 
-        CreateContainerResponse container2 = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999")
-                .withName("container2").withLinks(new Link("container1", "container1Link")).exec();
+	@Test
+	public void startContainerWithLinkingDeprecated() throws DockerException {
 
-        LOG.info("Created container2 {}", container2.toString());
-        assertThat(container2.getId(), not(isEmptyString()));
+		CreateContainerResponse container1 = dockerClient
+				.createContainerCmd("busybox").withCmd("sleep", "9999")
+				.withName("container1").exec();
 
-        dockerClient.startContainerCmd(container2.getId()).exec();
+		LOG.info("Created container1 {}", container1.toString());
+		assertThat(container1.getId(), not(isEmptyString()));
 
-        InspectContainerResponse inspectContainerResponse2 = dockerClient.inspectContainerCmd(container2.getId())
-                .exec();
-        LOG.info("Container2 Inspect: {}", inspectContainerResponse2.toString());
+		dockerClient.startContainerCmd(container1.getId()).exec();
 
-        assertThat(inspectContainerResponse2.getConfig(), is(notNullValue()));
-        assertThat(inspectContainerResponse2.getId(), not(isEmptyString()));
-        assertThat(inspectContainerResponse2.getHostConfig(), is(notNullValue()));
-        assertThat(inspectContainerResponse2.getHostConfig().getLinks(), is(notNullValue()));
-        assertThat(inspectContainerResponse2.getHostConfig().getLinks(), equalTo(new Link[] { new Link("container1",
-                "container1Link") }));
-        assertThat(inspectContainerResponse2.getId(), startsWith(container2.getId()));
-        assertThat(inspectContainerResponse2.getName(), equalTo("/container2"));
-        assertThat(inspectContainerResponse2.getImageId(), not(isEmptyString()));
-        assertThat(inspectContainerResponse2.getState(), is(notNullValue()));
-        assertThat(inspectContainerResponse2.getState().isRunning(), is(true));
+		InspectContainerResponse inspectContainerResponse1 = dockerClient
+				.inspectContainerCmd(container1.getId()).exec();
+		LOG.info("Container1 Inspect: {}", inspectContainerResponse1.toString());
 
-    }
+		assertThat(inspectContainerResponse1.getConfig(), is(notNullValue()));
+		assertThat(inspectContainerResponse1.getId(), not(isEmptyString()));
+		assertThat(inspectContainerResponse1.getId(),
+				startsWith(container1.getId()));
+		assertThat(inspectContainerResponse1.getName(), equalTo("/container1"));
+		assertThat(inspectContainerResponse1.getImageId(), not(isEmptyString()));
+		assertThat(inspectContainerResponse1.getState(), is(notNullValue()));
+		assertThat(inspectContainerResponse1.getState().isRunning(), is(true));
 
-    @Test
-    public void startContainerWithLinking() throws DockerException {
+		if (!inspectContainerResponse1.getState().isRunning()) {
+			assertThat(inspectContainerResponse1.getState().getExitCode(),
+					is(equalTo(0)));
+		}
 
-        CreateContainerResponse container1 = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999")
-                .withName("container1").exec();
+		CreateContainerResponse container2 = dockerClient
+				.createContainerCmd("busybox").withCmd("sleep", "9999")
+				.withName("container2").exec();
 
-        LOG.info("Created container1 {}", container1.toString());
-        assertThat(container1.getId(), not(isEmptyString()));
+		LOG.info("Created container2 {}", container2.toString());
+		assertThat(container2.getId(), not(isEmptyString()));
 
-        dockerClient.startContainerCmd(container1.getId()).exec();
+		dockerClient.startContainerCmd(container2.getId())
+				.withLinks(new Link("container1", "container1Link")).exec();
 
-        InspectContainerResponse inspectContainerResponse1 = dockerClient.inspectContainerCmd(container1.getId())
-                .exec();
-        LOG.info("Container1 Inspect: {}", inspectContainerResponse1.toString());
+		InspectContainerResponse inspectContainerResponse2 = dockerClient
+				.inspectContainerCmd(container2.getId()).exec();
+		LOG.info("Container2 Inspect: {}", inspectContainerResponse2.toString());
 
-        assertThat(inspectContainerResponse1.getConfig(), is(notNullValue()));
-        assertThat(inspectContainerResponse1.getId(), not(isEmptyString()));
-        assertThat(inspectContainerResponse1.getId(), startsWith(container1.getId()));
-        assertThat(inspectContainerResponse1.getName(), equalTo("/container1"));
-        assertThat(inspectContainerResponse1.getImageId(), not(isEmptyString()));
-        assertThat(inspectContainerResponse1.getState(), is(notNullValue()));
-        assertThat(inspectContainerResponse1.getState().isRunning(), is(true));
+		assertThat(inspectContainerResponse2.getConfig(), is(notNullValue()));
+		assertThat(inspectContainerResponse2.getId(), not(isEmptyString()));
+		assertThat(inspectContainerResponse2.getHostConfig(),
+				is(notNullValue()));
+		assertThat(inspectContainerResponse2.getHostConfig().getLinks(),
+				is(notNullValue()));
+		assertThat(
+				inspectContainerResponse2.getHostConfig().getLinks(),
+				equalTo(new Link[] { new Link("container1", "container1Link") }));
+		assertThat(inspectContainerResponse2.getId(),
+				startsWith(container2.getId()));
+		assertThat(inspectContainerResponse2.getName(), equalTo("/container2"));
+		assertThat(inspectContainerResponse2.getImageId(), not(isEmptyString()));
+		assertThat(inspectContainerResponse2.getState(), is(notNullValue()));
+		assertThat(inspectContainerResponse2.getState().isRunning(), is(true));
 
-        if (!inspectContainerResponse1.getState().isRunning()) {
-            assertThat(inspectContainerResponse1.getState().getExitCode(), is(equalTo(0)));
-        }
+	}
+
+	@Test
+	public void startContainerWithLinking() throws DockerException {
+
+		CreateContainerResponse container1 = dockerClient
+				.createContainerCmd("busybox").withCmd("sleep", "9999")
+				.withName("container1").exec();
+
+		LOG.info("Created container1 {}", container1.toString());
+		assertThat(container1.getId(), not(isEmptyString()));
+
+		dockerClient.startContainerCmd(container1.getId()).exec();
+
+		InspectContainerResponse inspectContainerResponse1 = dockerClient
+				.inspectContainerCmd(container1.getId()).exec();
+		LOG.info("Container1 Inspect: {}", inspectContainerResponse1.toString());
+
+		assertThat(inspectContainerResponse1.getConfig(), is(notNullValue()));
+		assertThat(inspectContainerResponse1.getId(), not(isEmptyString()));
+		assertThat(inspectContainerResponse1.getId(),
+				startsWith(container1.getId()));
+		assertThat(inspectContainerResponse1.getName(), equalTo("/container1"));
+		assertThat(inspectContainerResponse1.getImageId(), not(isEmptyString()));
+		assertThat(inspectContainerResponse1.getState(), is(notNullValue()));
+		assertThat(inspectContainerResponse1.getState().isRunning(), is(true));
+
+		if (!inspectContainerResponse1.getState().isRunning()) {
+			assertThat(inspectContainerResponse1.getState().getExitCode(),
+					is(equalTo(0)));
+		}
+
+		CreateContainerResponse container2 = dockerClient
+				.createContainerCmd("busybox").withCmd("sleep", "9999")
+				.withName("container2")
+				.withLinks(new Link("container1", "container1Link")).exec();
+
+		LOG.info("Created container2 {}", container2.toString());
+		assertThat(container2.getId(), not(isEmptyString()));
+
+		dockerClient.startContainerCmd(container2.getId()).exec();
+
+		InspectContainerResponse inspectContainerResponse2 = dockerClient
+				.inspectContainerCmd(container2.getId()).exec();
+		LOG.info("Container2 Inspect: {}", inspectContainerResponse2.toString());
+
+		assertThat(inspectContainerResponse2.getConfig(), is(notNullValue()));
+		assertThat(inspectContainerResponse2.getId(), not(isEmptyString()));
+		assertThat(inspectContainerResponse2.getHostConfig(),
+				is(notNullValue()));
+		assertThat(inspectContainerResponse2.getHostConfig().getLinks(),
+				is(notNullValue()));
+		assertThat(
+				inspectContainerResponse2.getHostConfig().getLinks(),
+				equalTo(new Link[] { new Link("container1", "container1Link") }));
+		assertThat(inspectContainerResponse2.getId(),
+				startsWith(container2.getId()));
+		assertThat(inspectContainerResponse2.getName(), equalTo("/container2"));
+		assertThat(inspectContainerResponse2.getImageId(), not(isEmptyString()));
+		assertThat(inspectContainerResponse2.getState(), is(notNullValue()));
+		assertThat(inspectContainerResponse2.getState().isRunning(), is(true));
+
+	}
+
+	@Test
+	public void startContainer() throws DockerException {
+
+		CreateContainerResponse container = dockerClient
+				.createContainerCmd("busybox").withCmd(new String[] { "top" })
+				.exec();
 
-        CreateContainerResponse container2 = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999")
-                .withName("container2").withLinks(new Link("container1", "container1Link")).exec();
+		LOG.info("Created container {}", container.toString());
+		assertThat(container.getId(), not(isEmptyString()));
 
-        LOG.info("Created container2 {}", container2.toString());
-        assertThat(container2.getId(), not(isEmptyString()));
+		dockerClient.startContainerCmd(container.getId()).exec();
 
-        dockerClient.startContainerCmd(container2.getId()).exec();
+		InspectContainerResponse inspectContainerResponse = dockerClient
+				.inspectContainerCmd(container.getId()).exec();
+		LOG.info("Container Inspect: {}", inspectContainerResponse.toString());
 
-        InspectContainerResponse inspectContainerResponse2 = dockerClient.inspectContainerCmd(container2.getId())
-                .exec();
-        LOG.info("Container2 Inspect: {}", inspectContainerResponse2.toString());
+		assertThat(inspectContainerResponse.getConfig(), is(notNullValue()));
+		assertThat(inspectContainerResponse.getId(), not(isEmptyString()));
 
-        assertThat(inspectContainerResponse2.getConfig(), is(notNullValue()));
-        assertThat(inspectContainerResponse2.getId(), not(isEmptyString()));
-        assertThat(inspectContainerResponse2.getHostConfig(), is(notNullValue()));
-        assertThat(inspectContainerResponse2.getHostConfig().getLinks(), is(notNullValue()));
-        assertThat(inspectContainerResponse2.getHostConfig().getLinks(), equalTo(new Link[] { new Link("container1",
-                "container1Link") }));
-        assertThat(inspectContainerResponse2.getId(), startsWith(container2.getId()));
-        assertThat(inspectContainerResponse2.getName(), equalTo("/container2"));
-        assertThat(inspectContainerResponse2.getImageId(), not(isEmptyString()));
-        assertThat(inspectContainerResponse2.getState(), is(notNullValue()));
-        assertThat(inspectContainerResponse2.getState().isRunning(), is(true));
+		assertThat(inspectContainerResponse.getId(),
+				startsWith(container.getId()));
 
-    }
+		assertThat(inspectContainerResponse.getImageId(), not(isEmptyString()));
+		assertThat(inspectContainerResponse.getState(), is(notNullValue()));
 
-    @Test
-    public void startContainer() throws DockerException {
+		assertThat(inspectContainerResponse.getState().isRunning(), is(true));
 
-        CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd(new String[] { "top" })
-                .exec();
+		if (!inspectContainerResponse.getState().isRunning()) {
+			assertThat(inspectContainerResponse.getState().getExitCode(),
+					is(equalTo(0)));
+		}
+	}
 
-        LOG.info("Created container {}", container.toString());
-        assertThat(container.getId(), not(isEmptyString()));
+	@Test
+	public void testStartNonExistingContainer() throws DockerException {
+		try {
+			dockerClient.startContainerCmd("non-existing").exec();
+			fail("expected NotFoundException");
+		} catch (NotFoundException e) {
+		}
+	}
 
-        dockerClient.startContainerCmd(container.getId()).exec();
+	/**
+	 * This tests support for --net option for the docker run command:
+	 * --net="bridge" Set the Network mode for the container 'bridge': creates a
+	 * new network stack for the container on the docker bridge 'none': no
+	 * networking for this container 'container:': reuses another container
+	 * network stack 'host': use the host network stack inside the container.
+	 * Note: the host mode gives the container full access to local system
+	 * services such as D-bus and is therefore considered insecure.
+	 */
+	@Test
+	public void startContainerWithNetworkMode() throws DockerException {
 
-        InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
-        LOG.info("Container Inspect: {}", inspectContainerResponse.toString());
+		CreateContainerResponse container = dockerClient
+				.createContainerCmd("busybox").withCmd("true").exec();
 
-        assertThat(inspectContainerResponse.getConfig(), is(notNullValue()));
-        assertThat(inspectContainerResponse.getId(), not(isEmptyString()));
+		LOG.info("Created container {}", container.toString());
 
-        assertThat(inspectContainerResponse.getId(), startsWith(container.getId()));
+		assertThat(container.getId(), not(isEmptyString()));
 
-        assertThat(inspectContainerResponse.getImageId(), not(isEmptyString()));
-        assertThat(inspectContainerResponse.getState(), is(notNullValue()));
+		InspectContainerResponse inspectContainerResponse = dockerClient
+				.inspectContainerCmd(container.getId()).exec();
 
-        assertThat(inspectContainerResponse.getState().isRunning(), is(true));
+		dockerClient.startContainerCmd(container.getId())
+				.withNetworkMode("host").exec();
 
-        if (!inspectContainerResponse.getState().isRunning()) {
-            assertThat(inspectContainerResponse.getState().getExitCode(), is(equalTo(0)));
-        }
-    }
+		inspectContainerResponse = dockerClient.inspectContainerCmd(
+				container.getId()).exec();
 
-    @Test
-    public void testStartNonExistingContainer() throws DockerException {
-        try {
-            dockerClient.startContainerCmd("non-existing").exec();
-            fail("expected NotFoundException");
-        } catch (NotFoundException e) {
-        }
-    }
+		assertThat(inspectContainerResponse.getHostConfig().getNetworkMode(),
+				is(equalTo("host")));
+	}
 
-    /**
-     * This tests support for --net option for the docker run command: --net="bridge" Set the Network mode for the
-     * container 'bridge': creates a new network stack for the container on the docker bridge 'none': no networking for
-     * this container 'container:': reuses another container network stack 'host': use the host network stack inside the
-     * container. Note: the host mode gives the container full access to local system services such as D-bus and is
-     * therefore considered insecure.
-     */
-    @Test
-    public void startContainerWithNetworkMode() throws DockerException {
+	@Test
+	public void startContainerWithCapAddAndCapDrop() throws DockerException {
 
-        CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("true")
-                .withNetworkMode("host").exec();
+		CreateContainerResponse container = dockerClient
+				.createContainerCmd("busybox").withCmd("sleep", "9999").exec();
 
-        LOG.info("Created container {}", container.toString());
+		LOG.info("Created container {}", container.toString());
 
-        assertThat(container.getId(), not(isEmptyString()));
+		assertThat(container.getId(), not(isEmptyString()));
 
-        InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
+		dockerClient.startContainerCmd(container.getId()).withCapAdd(NET_ADMIN)
+				.withCapDrop(MKNOD).exec();
 
-        dockerClient.startContainerCmd(container.getId()).exec();
+		InspectContainerResponse inspectContainerResponse = dockerClient
+				.inspectContainerCmd(container.getId()).exec();
 
-        inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
+		assertThat(inspectContainerResponse.getState().isRunning(), is(true));
 
-        assertThat(inspectContainerResponse.getHostConfig().getNetworkMode(), is(equalTo("host")));
-    }
+		assertThat(Arrays.asList(inspectContainerResponse.getHostConfig()
+				.getCapAdd()), contains(NET_ADMIN));
 
-    @Test
-    public void startContainerWithCapAddAndCapDrop() throws DockerException {
+		assertThat(Arrays.asList(inspectContainerResponse.getHostConfig()
+				.getCapDrop()), contains(MKNOD));
+	}
 
-        CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999")
-                .withCapAdd(NET_ADMIN).withCapDrop(MKNOD).exec();
+	@Test
+	public void startContainerWithDevices() throws DockerException {
 
-        LOG.info("Created container {}", container.toString());
+		CreateContainerResponse container = dockerClient
+				.createContainerCmd("busybox").withCmd("sleep", "9999").exec();
 
-        assertThat(container.getId(), not(isEmptyString()));
+		LOG.info("Created container {}", container.toString());
 
-        dockerClient.startContainerCmd(container.getId()).exec();
+		assertThat(container.getId(), not(isEmptyString()));
 
-        InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
+		dockerClient.startContainerCmd(container.getId())
+				.withDevices(new Device("rwm", "/dev/nulo", "/dev/zero"))
+				.exec();
 
-        assertThat(inspectContainerResponse.getState().isRunning(), is(true));
+		InspectContainerResponse inspectContainerResponse = dockerClient
+				.inspectContainerCmd(container.getId()).exec();
 
-        assertThat(Arrays.asList(inspectContainerResponse.getHostConfig().getCapAdd()), contains(NET_ADMIN));
+		assertThat(inspectContainerResponse.getState().isRunning(), is(true));
 
-        assertThat(Arrays.asList(inspectContainerResponse.getHostConfig().getCapDrop()), contains(MKNOD));
-    }
+		assertThat(Arrays.asList(inspectContainerResponse.getHostConfig()
+				.getDevices()), contains(new Device("rwm", "/dev/nulo",
+				"/dev/zero")));
+	}
 
-    @Test
-    public void startContainerWithDevices() throws DockerException {
+	@Test
+	public void startContainerWithExtraHosts() throws DockerException {
 
-        CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999")
-                .withDevices(new Device("rwm", "/dev/nulo", "/dev/zero")).exec();
+		CreateContainerResponse container = dockerClient
+				.createContainerCmd("busybox").withCmd("sleep", "9999").exec();
 
-        LOG.info("Created container {}", container.toString());
+		LOG.info("Created container {}", container.toString());
 
-        assertThat(container.getId(), not(isEmptyString()));
+		assertThat(container.getId(), not(isEmptyString()));
 
-        dockerClient.startContainerCmd(container.getId()).exec();
+		dockerClient.startContainerCmd(container.getId())
+				.withExtraHosts("dockerhost:127.0.0.1").exec();
 
-        InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
+		InspectContainerResponse inspectContainerResponse = dockerClient
+				.inspectContainerCmd(container.getId()).exec();
 
-        assertThat(inspectContainerResponse.getState().isRunning(), is(true));
+		assertThat(inspectContainerResponse.getState().isRunning(), is(true));
 
-        assertThat(Arrays.asList(inspectContainerResponse.getHostConfig().getDevices()), contains(new Device("rwm",
-                "/dev/nulo", "/dev/zero")));
-    }
+		assertThat(Arrays.asList(inspectContainerResponse.getHostConfig()
+				.getExtraHosts()), contains("dockerhost:127.0.0.1"));
+	}
 
-    @Test
-    public void startContainerWithExtraHosts() throws DockerException {
+	@Test
+	public void startContainerWithRestartPolicy() throws DockerException {
 
-        CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999")
-                .withExtraHosts("dockerhost:127.0.0.1").exec();
+		CreateContainerResponse container = dockerClient
+				.createContainerCmd("busybox").withCmd("sleep", "9999").exec();
 
-        LOG.info("Created container {}", container.toString());
+		LOG.info("Created container {}", container.toString());
 
-        assertThat(container.getId(), not(isEmptyString()));
+		assertThat(container.getId(), not(isEmptyString()));
 
-        dockerClient.startContainerCmd(container.getId()).exec();
+		RestartPolicy restartPolicy = RestartPolicy.onFailureRestart(5);
 
-        InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
+		dockerClient.startContainerCmd(container.getId())
+				.withRestartPolicy(restartPolicy).exec();
 
-        assertThat(inspectContainerResponse.getState().isRunning(), is(true));
+		InspectContainerResponse inspectContainerResponse = dockerClient
+				.inspectContainerCmd(container.getId()).exec();
 
-        assertThat(Arrays.asList(inspectContainerResponse.getHostConfig().getExtraHosts()),
-                contains("dockerhost:127.0.0.1"));
-    }
+		assertThat(inspectContainerResponse.getState().isRunning(), is(true));
 
-    @Test
-    public void startContainerWithRestartPolicy() throws DockerException {
+		assertThat(inspectContainerResponse.getHostConfig().getRestartPolicy(),
+				is(equalTo(restartPolicy)));
+	}
 
-        RestartPolicy restartPolicy = RestartPolicy.onFailureRestart(5);
+	@Test
+	public void existingHostConfigIsPreservedByBlankStartCmd()
+			throws DockerException {
 
-        CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999")
-                .withRestartPolicy(restartPolicy).exec();
+		String dnsServer = "8.8.8.8";
 
-        LOG.info("Created container {}", container.toString());
+		// prepare a container with custom DNS
+		CreateContainerResponse container = dockerClient
+				.createContainerCmd("busybox").withDns(dnsServer)
+				.withCmd("true").exec();
 
-        assertThat(container.getId(), not(isEmptyString()));
+		LOG.info("Created container {}", container.toString());
 
-        dockerClient.startContainerCmd(container.getId()).exec();
+		assertThat(container.getId(), not(isEmptyString()));
 
-        InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
+		// start container _without_any_customization_ (important!)
+		dockerClient.startContainerCmd(container.getId()).exec();
 
-        assertThat(inspectContainerResponse.getState().isRunning(), is(true));
+		InspectContainerResponse inspectContainerResponse = dockerClient
+				.inspectContainerCmd(container.getId()).exec();
 
-        assertThat(inspectContainerResponse.getHostConfig().getRestartPolicy(), is(equalTo(restartPolicy)));
-    }
+		// The DNS setting survived.
+		assertThat(inspectContainerResponse.getHostConfig().getDns(),
+				is(notNullValue()));
+		assertThat(Arrays.asList(inspectContainerResponse.getHostConfig()
+				.getDns()), contains(dnsServer));
+	}
 
-    @Test
-    public void existingHostConfigIsPreservedByBlankStartCmd() throws DockerException {
+	@Test
+	public void existingHostConfigIsResetByConfiguredStartCmd()
+			throws DockerException {
+		// As of version 1.3.2, Docker assumes that you either configure a
+		// container
+		// when creating it or when starting it, but not mixing both.
+		// See https://github.com/docker-java/docker-java/pull/111
+		// If this test starts to fail, this behavior changed and a review of
+		// implementation
+		// and documentation might be needed.
 
-        String dnsServer = "8.8.8.8";
+		String dnsServer = "8.8.8.8";
 
-        // prepare a container with custom DNS
-        CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withDns(dnsServer)
-                .withCmd("true").exec();
+		// prepare a container with custom DNS
+		CreateContainerResponse container = dockerClient
+				.createContainerCmd("busybox").withDns(dnsServer)
+				.withCmd("true").exec();
 
-        LOG.info("Created container {}", container.toString());
+		LOG.info("Created container {}", container.toString());
 
-        assertThat(container.getId(), not(isEmptyString()));
+		assertThat(container.getId(), not(isEmptyString()));
 
-        // start container _without_any_customization_ (important!)
-        dockerClient.startContainerCmd(container.getId()).exec();
+		// modify another setting in start command. Leave DNS unchanged.
+		dockerClient.startContainerCmd(container.getId())
+				.withPublishAllPorts(true).exec();
 
-        InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
+		InspectContainerResponse inspectContainerResponse = dockerClient
+				.inspectContainerCmd(container.getId()).exec();
 
-        // The DNS setting survived.
-        assertThat(inspectContainerResponse.getHostConfig().getDns(), is(notNullValue()));
-        assertThat(Arrays.asList(inspectContainerResponse.getHostConfig().getDns()), contains(dnsServer));
-    }
+		// although start did not modify DNS Settings, they were reset to their
+		// default.
+		assertThat(inspectContainerResponse.getHostConfig().getDns(),
+				is(nullValue(String[].class)));
+	}
 
-    @Test
-    public void anUnconfiguredCommandSerializesToEmptyJson() throws Exception {
-        ObjectMapper objectMapper = new ObjectMapper();
-        StartContainerCmd command = dockerClient.startContainerCmd("");
-        assertThat(objectMapper.writeValueAsString(command), is("{}"));
-    }
+	@Test
+	public void anUnconfiguredCommandSerializesToEmptyJson() throws Exception {
+		ObjectMapper objectMapper = new ObjectMapper();
+		StartContainerCmd command = dockerClient.startContainerCmd("");
+		assertThat(objectMapper.writeValueAsString(command), is("{}"));
+	}
 }