Skip to content
Closed
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
16 changes: 16 additions & 0 deletions src/main/java/com/github/dockerjava/api/model/HostConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ public class HostConfig implements Serializable {
@JsonProperty("PidMode")
private String pidMode;

@JsonProperty("PidsLimit")
private Integer pidsLimit;

/**
* @since {@link RemoteApiVersion#VERSION_1_20}
*/
Expand Down Expand Up @@ -295,6 +298,11 @@ public String getPidMode() {
return pidMode;
}

@CheckForNull
public Integer getPidsLimit() {
return pidsLimit;
}

/**
* @see #blkioDeviceReadBps
*/
Expand Down Expand Up @@ -691,6 +699,14 @@ public HostConfig withPidMode(String pidMode) {
return this;
}

/**
* @see #pidsLimit
*/
public HostConfig withPidsLimit(Integer pidsLimit) {
this.pidsLimit = pidsLimit;
return this;
}

/**
* @see #portBindings
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,25 @@ public void createContainerWithPidMode() throws DockerException {
assertThat(inspectContainerResponse.getHostConfig().getPidMode(), is(equalTo("host")));
}

/**
* This test is intended to test the pidLimit option that will help prevent fork bombs and will prevent one container from taking the rest
*/
@Test
public void createContainerWithPidsLimit() throws DockerException {

HostConfig hostConfig = new HostConfig().withPidsLimit(1024);

CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withHostConfig(hostConfig).withCmd("true").exec();

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

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

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

assertThat(inspectContainerResponse.getHostConfig().getPidsLimit(), is(equalTo(1024)));
}

/**
* 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 this container 'container:': reuses
Expand Down