X Tutup
Skip to content

Commit 8e44173

Browse files
author
Sean Fitts
committed
Add option to reuse existing host config on start
1 parent e0c8124 commit 8e44173

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

src/main/java/com/github/dockerjava/api/command/StartContainerCmd.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ public interface StartContainerCmd extends DockerCmd<Void> {
113113
* "CHOWN" prevents the container from changing the owner of any files.
114114
*/
115115
public StartContainerCmd withCapDrop(String... capDrop);
116+
117+
/**
118+
* Perform the start using the existing host configuration for the container.
119+
*
120+
* @param withExisting <code>true</code> if the container's existing configuration should be used.
121+
*
122+
* @return
123+
*/
124+
public StartContainerCmd withExistingConfig(boolean withExisting);
125+
126+
/**
127+
* @return <code>true</code> if the container should use its existing configuration.
128+
*/
129+
public boolean useExistingConfig();
116130

117131
/**
118132
* @throws NotFoundException

src/main/java/com/github/dockerjava/core/command/StartContainerCmdImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public class StartContainerCmdImpl extends AbstrDockerCmd<StartContainerCmd, Voi
6666
@JsonProperty("CapDrop")
6767
private String[] capDrop;
6868

69+
@JsonIgnore
70+
private boolean useExistingConfig = false;
71+
6972
public StartContainerCmdImpl(StartContainerCmd.Exec exec, String containerId) {
7073
super(exec);
7174
withContainerId(containerId);
@@ -255,6 +258,17 @@ public StartContainerCmd withCapDrop(String... capDrop) {
255258
this.capDrop = capDrop;
256259
return this;
257260
}
261+
262+
@Override
263+
public StartContainerCmd withExistingConfig(boolean useExisting) {
264+
this.useExistingConfig = useExisting;
265+
return this;
266+
}
267+
268+
@Override
269+
public boolean useExistingConfig() {
270+
return this.useExistingConfig;
271+
}
258272

259273
@Override
260274
public String toString() {

src/main/java/com/github/dockerjava/jaxrs1/StartContainerCmdExec.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.github.dockerjava.api.BadRequestException;
1313
import com.github.dockerjava.api.command.StartContainerCmd;
1414
import com.sun.jersey.api.client.WebResource;
15+
import com.sun.jersey.api.client.WebResource.Builder;
1516

1617
public class StartContainerCmdExec extends AbstrDockerCmdExec<StartContainerCmd, Void> implements StartContainerCmd.Exec {
1718

@@ -27,19 +28,20 @@ protected Void execute(StartContainerCmd command) {
2728
.resolveTemplate("/containers/{id}/start", command.getContainerId())
2829
.build();
2930

30-
// Workaround for Docker issue 6231. This avoids the use of chunked encoding.
31-
ObjectMapper mapper = new ObjectMapper();
32-
ByteArrayInputStream bais;
33-
try {
34-
bais = new ByteArrayInputStream(mapper.writeValueAsBytes(command));
35-
} catch (JsonProcessingException jpe) {
36-
throw new BadRequestException("Unable to serialize start command", jpe);
37-
}
31+
Builder builder = webResource.accept(MediaType.APPLICATION_JSON);
32+
if (!command.useExistingConfig()) {
33+
// Workaround for Docker issue 6231. This avoids the use of chunked encoding.
34+
ObjectMapper mapper = new ObjectMapper();
35+
ByteArrayInputStream bais;
36+
try {
37+
bais = new ByteArrayInputStream(mapper.writeValueAsBytes(command));
38+
} catch (JsonProcessingException jpe) {
39+
throw new BadRequestException("Unable to serialize start command", jpe);
40+
}
41+
builder = builder.entity(bais, MediaType.APPLICATION_JSON);
42+
}
3843
LOGGER.trace("POST: {}", webResource);
39-
webResource.accept(MediaType.APPLICATION_JSON)
40-
.entity(bais, MediaType.APPLICATION_JSON)
41-
.post();
42-
44+
builder.post();
4345
return null;
4446
}
4547

0 commit comments

Comments
 (0)
X Tutup