Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/com/github/dockerjava/api/DockerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ public CreateImageCmd createImageCmd(String repository,

public CreateContainerCmd createContainerCmd(String image);

/**
* Creates a new {@link StartContainerCmd} for the container with the
* given ID.
* The command can then be further customized by using builder
* methods on it like {@link StartContainerCmd#withDns(String...)}.
* <p>
* <b>If you customize the command, any existing configuration of the
* target container will get reset to its default before applying the
* new configuration. To preserve the existing configuration, use an
* unconfigured {@link StartContainerCmd}.</b>
* <p>
* This command corresponds to the <code>/containers/{id}/start</code>
* endpoint of the Docker Remote API.
*/
public StartContainerCmd startContainerCmd(String containerId);

public InspectContainerCmd inspectContainerCmd(String containerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
import java.lang.reflect.Method;
import java.util.*;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.dockerjava.api.DockerException;
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.*;

import org.testng.ITestResult;
Expand Down Expand Up @@ -416,6 +418,11 @@ public void existingHostConfigIsPreservedByBlankStartCmd() throws DockerExceptio

@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";

Expand All @@ -438,4 +445,11 @@ public void existingHostConfigIsResetByConfiguredStartCmd() throws DockerExcepti
// 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("{}"));
}
}