X Tutup
Skip to content

Commit 3415582

Browse files
committed
Test for serialization of an unconfigured StartContainerCmd,
documentation
1 parent 5a7014f commit 3415582

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/main/java/com/github/dockerjava/api/DockerClient.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ public CreateImageCmd createImageCmd(String repository,
7979

8080
public CreateContainerCmd createContainerCmd(String image);
8181

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

8498
public InspectContainerCmd inspectContainerCmd(String containerId);

src/test/java/com/github/dockerjava/core/command/StartContainerCmdImplTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
import java.lang.reflect.Method;
1616
import java.util.*;
1717

18+
import com.fasterxml.jackson.databind.ObjectMapper;
1819
import com.github.dockerjava.api.DockerException;
1920
import com.github.dockerjava.api.NotFoundException;
2021
import com.github.dockerjava.api.command.CreateContainerResponse;
2122
import com.github.dockerjava.api.command.InspectContainerResponse;
23+
import com.github.dockerjava.api.command.StartContainerCmd;
2224
import com.github.dockerjava.api.model.*;
2325

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

417419
@Test
418420
public void existingHostConfigIsResetByConfiguredStartCmd() throws DockerException {
421+
// As of version 1.3.2, Docker assumes that you either configure a container
422+
// when creating it or when starting it, but not mixing both.
423+
// See https://github.com/docker-java/docker-java/pull/111
424+
// If this test starts to fail, this behavior changed and a review of implementation
425+
// and documentation might be needed.
419426

420427
String dnsServer = "8.8.8.8";
421428

@@ -438,4 +445,11 @@ public void existingHostConfigIsResetByConfiguredStartCmd() throws DockerExcepti
438445
// although start did not modify DNS Settings, they were reset to their default.
439446
assertThat(inspectContainerResponse.getHostConfig().getDns(), is(nullValue(String[].class)));
440447
}
448+
449+
@Test
450+
public void anUnconfiguredCommandSerializesToEmptyJson() throws Exception {
451+
ObjectMapper objectMapper = new ObjectMapper();
452+
StartContainerCmd command = dockerClient.startContainerCmd("");
453+
assertThat(objectMapper.writeValueAsString(command), is("{}"));
454+
}
441455
}

0 commit comments

Comments
 (0)
X Tutup