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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
@JsonProperty("StdinOnce") private boolean stdInOnce = false;
@JsonProperty("Env") private String[] env;
@JsonProperty("Cmd") private String[] cmd;
@JsonProperty("Dns") private String[] dns;
@JsonProperty("Image") private String image;
@JsonProperty("Volumes") private Volumes volumes = new Volumes();
@JsonProperty("VolumesFrom") private String[] volumesFrom = new String[]{};
Expand Down Expand Up @@ -257,13 +256,13 @@ public CreateContainerCmdImpl withCmd(String... cmd) {
}

@Override
public String[] getDns() {
return dns;
public String[] getDns() {
return hostConfig.getDns();
}

@Override
public CreateContainerCmdImpl withDns(String... dns) {
this.dns = dns;
public CreateContainerCmdImpl withDns(String... dns) {
hostConfig.setDns(dns);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,25 @@ public void createContainerWithCapAddAndCapDrop() throws DockerException {
.getCapDrop()), contains(MKNOD));
}

@Test
public void createContainerWithDns() throws DockerException {

String aDnsServer = "8.8.8.8";
String anotherDnsServer = "8.8.4.4";

CreateContainerResponse container = dockerClient
.createContainerCmd("busybox")
.withCmd("true").withDns(aDnsServer, anotherDnsServer).exec();

LOG.info("Created container {}", container.toString());

assertThat(container.getId(), not(isEmptyString()));

InspectContainerResponse inspectContainerResponse = dockerClient
.inspectContainerCmd(container.getId()).exec();

assertThat(Arrays.asList(inspectContainerResponse.getHostConfig().getDns()),
contains(aDnsServer, anotherDnsServer));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,15 @@ public void startContainerWithDns() throws DockerException {

CreateContainerResponse container = dockerClient
.createContainerCmd("busybox")
.withCmd("true").withDns(aDnsServer, anotherDnsServer).exec();
.withCmd("true").exec();

LOG.info("Created container {}", container.toString());

assertThat(container.getId(), not(isEmptyString()));

InspectContainerResponse inspectContainerResponse = dockerClient
.inspectContainerCmd(container.getId()).exec();

dockerClient.startContainerCmd(container.getId()).withDns(aDnsServer, anotherDnsServer).exec();

inspectContainerResponse = dockerClient.inspectContainerCmd(container
InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container
.getId()).exec();

assertThat(Arrays.asList(inspectContainerResponse.getHostConfig().getDns()),
Expand Down