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 @@ -18,6 +18,8 @@
import com.github.dockerjava.api.model.Volume;
import com.github.dockerjava.api.model.VolumesFrom;

import javax.annotation.CheckForNull;

public interface CreateContainerCmd extends SyncDockerCmd<CreateContainerResponse> {

public static interface Exec extends DockerCmdSyncExec<CreateContainerCmd, CreateContainerResponse> {
Expand Down Expand Up @@ -134,6 +136,9 @@ public static interface Exec extends DockerCmdSyncExec<CreateContainerCmd, Creat

public boolean isTty();

@CheckForNull
public String getPidMode();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotate with @CheckForNull


public CreateContainerCmd withAttachStderr(boolean attachStderr);

public CreateContainerCmd withAttachStdin(boolean attachStdin);
Expand Down Expand Up @@ -291,6 +296,7 @@ public static interface Exec extends DockerCmdSyncExec<CreateContainerCmd, Creat

public CreateContainerCmd withContainerIDFile(String containerIDFile);

public CreateContainerCmd withPid(String pidMode);
/**
* @return
*/
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/com/github/dockerjava/api/model/HostConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import javax.annotation.CheckForNull;

@JsonIgnoreProperties(ignoreUnknown = true)
public class HostConfig {

Expand Down Expand Up @@ -75,13 +77,17 @@ public class HostConfig {
@JsonProperty("CpuShares")
private int cpuShares = 0;

@JsonProperty("PidMode")
private String pidMode;

public HostConfig() {
}

public HostConfig(Bind[] binds, Link[] links, LxcConf[] lxcConf, LogConfig logConfig, Ports portBindings,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcuslinke do you need at all this huge constructor?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. Not needed. It's already removed in 'issue-246' branch. So no need to remove it here.

boolean publishAllPorts, boolean privileged, boolean readonlyRootfs, String[] dns, String[] dnsSearch,
VolumesFrom[] volumesFrom, String containerIDFile, Capability[] capAdd, Capability[] capDrop,
RestartPolicy restartPolicy, String networkMode, Device[] devices, String[] extraHosts, Ulimit[] ulimits) {
RestartPolicy restartPolicy, String networkMode, Device[] devices, String[] extraHosts, Ulimit[] ulimits,
String pidMode) {
this.binds = new Binds(binds);
this.links = new Links(links);
this.lxcConf = lxcConf;
Expand All @@ -101,6 +107,7 @@ public HostConfig(Bind[] binds, Link[] links, LxcConf[] lxcConf, LogConfig logCo
this.devices = devices;
this.extraHosts = extraHosts;
this.ulimits = ulimits;
this.pidMode = pidMode;
}

@JsonIgnore
Expand Down Expand Up @@ -194,6 +201,11 @@ public int getCpuShares() {
return cpuShares;
}

@CheckForNull
public String getPidMode() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CheckForNull here also required as it doesn't inherited by any interfaces

return pidMode;
}

@JsonIgnore
public void setBinds(Bind... binds) {
this.binds = new Binds(binds);
Expand Down Expand Up @@ -273,6 +285,10 @@ public void setUlimits(Ulimit[] ulimits) {
this.ulimits = ulimits;
}

public void setPidMode(String pidMode) {
this.pidMode = pidMode;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package com.github.dockerjava.core.command;

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.Map;

import org.apache.commons.lang.builder.ToStringBuilder;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.dockerjava.api.ConflictException;
Expand All @@ -28,6 +22,11 @@
import com.github.dockerjava.api.model.Volume;
import com.github.dockerjava.api.model.Volumes;
import com.github.dockerjava.api.model.VolumesFrom;
import org.apache.commons.lang.builder.ToStringBuilder;

import java.util.Map;

import static com.google.common.base.Preconditions.checkNotNull;

/**
*
Expand Down Expand Up @@ -397,6 +396,12 @@ public boolean isTty() {
return tty;
}

@Override
@JsonIgnore
public String getPidMode() {
return hostConfig.getPidMode();
}

@Override
public String toString() {
return new ToStringBuilder(this).append("create container ").append(name != null ? "name=" + name + " " : "")
Expand Down Expand Up @@ -733,4 +738,11 @@ public CreateContainerCmdImpl withWorkingDir(String workingDir) {
return this;
}

@Override
public CreateContainerCmd withPid(String pidMode) {
checkNotNull(pidMode, "pidMode was not specified");
this.hostConfig.setPidMode(pidMode);
return this;
}

}
4 changes: 2 additions & 2 deletions src/main/java/com/github/dockerjava/jaxrs/EventsCmdExec.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.github.dockerjava.jaxrs;

import static com.google.common.net.UrlEscapers.*;

import javax.ws.rs.client.WebTarget;

import org.slf4j.Logger;
Expand All @@ -14,6 +12,8 @@
import com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier;
import com.github.dockerjava.jaxrs.async.GETCallbackNotifier;

import static com.google.common.net.UrlEscapers.urlPathSegmentEscaper;

public class EventsCmdExec extends AbstrAsyncDockerCmdExec<EventsCmd, Event> implements EventsCmd.Exec {

private static final Logger LOGGER = LoggerFactory.getLogger(EventsCmdExec.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
package com.github.dockerjava.core.command;

import com.github.dockerjava.api.ConflictException;
import com.github.dockerjava.api.DockerException;
import com.github.dockerjava.api.command.CreateContainerResponse;
import com.github.dockerjava.api.command.InspectContainerResponse;
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.LogConfig;
import com.github.dockerjava.api.model.Ports;
import com.github.dockerjava.api.model.RestartPolicy;
import com.github.dockerjava.api.model.Ulimit;
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.client.AbstractDockerClientTest;
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 static com.github.dockerjava.api.model.Capability.MKNOD;
import static com.github.dockerjava.api.model.Capability.NET_ADMIN;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -21,31 +45,9 @@
import java.util.Map;
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 com.github.dockerjava.api.ConflictException;
import com.github.dockerjava.api.DockerException;
import com.github.dockerjava.api.command.CreateContainerResponse;
import com.github.dockerjava.api.command.InspectContainerResponse;
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.HostConfig;
import com.github.dockerjava.api.model.Link;
import com.github.dockerjava.api.model.LogConfig;
import com.github.dockerjava.api.model.Ports;
import com.github.dockerjava.api.model.RestartPolicy;
import com.github.dockerjava.api.model.Ulimit;
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.client.AbstractDockerClientTest;
import static com.github.dockerjava.api.model.Capability.MKNOD;
import static com.github.dockerjava.api.model.Capability.NET_ADMIN;
import static org.hamcrest.MatcherAssert.assertThat;

@Test(groups = "integration")
public class CreateContainerCmdImplTest extends AbstractDockerClientTest {
Expand Down Expand Up @@ -451,6 +453,21 @@ public void createContainerWithRestartPolicy() throws DockerException {
assertThat(inspectContainerResponse.getHostConfig().getRestartPolicy(), is(equalTo(restartPolicy)));
}

@Test
public void createContainerWithPidMode() throws DockerException {

CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("true")
.withPid("host").exec();

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

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

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

assertThat(inspectContainerResponse.getHostConfig().getPidMode(), 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
Expand Down