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
22 changes: 22 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 @@ -194,6 +194,12 @@ public class HostConfig implements Serializable {
@JsonProperty("ShmSize")
private Long shmSize;

/**
* @since ~{@link RemoteApiVersion#VERSION_1_23}
*/
@JsonProperty("PidsLimit")
private Long pidsLimit;


@JsonIgnore
public Bind[] getBinds() {
Expand Down Expand Up @@ -415,6 +421,14 @@ public String getVolumeDriver() {
return volumeDriver;
}

/**
* @see #pidsLimit
*/
@CheckForNull
public Long getPidsLimit() {
return pidsLimit;
}

/**
* Parse the network mode as specified at
* {@see https://github.com/docker/engine-api/blob/master/types/container/hostconfig_unix.go}
Expand Down Expand Up @@ -794,6 +808,14 @@ public HostConfig withVolumesFrom(VolumesFrom[] volumesFrom) {
this.volumesFrom = volumesFrom;
return this;
}

/**
* @see #pidsLimit
*/
public HostConfig withPidsLimit(Long pidsLimit) {
this.pidsLimit = pidsLimit;
return this;
}
// end of auto-generated

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import com.github.dockerjava.api.model.Ports.Binding;
import com.github.dockerjava.client.AbstractDockerClientTest;

import com.github.dockerjava.core.RemoteApiVersion;
import org.apache.commons.io.FileUtils;
import org.testng.ITestResult;
import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
Expand All @@ -34,14 +36,14 @@
import java.lang.reflect.Method;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import static com.github.dockerjava.api.model.Capability.MKNOD;
import static com.github.dockerjava.api.model.Capability.NET_ADMIN;
import static com.github.dockerjava.utils.TestUtils.getVersion;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
Expand Down Expand Up @@ -751,6 +753,28 @@ public void createContainerWithShmSize() throws DockerException {

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

assertEquals(inspectContainerResponse.getHostConfig().getShmSize(), hostConfig.getShmSize());
assertThat(inspectContainerResponse.getHostConfig().getShmSize(), is(hostConfig.getShmSize()));
}

@SuppressWarnings("Duplicates")
@Test
public void createContainerWithShmPidsLimit() throws DockerException {
final RemoteApiVersion apiVersion = getVersion(dockerClient);

if (!apiVersion.isGreaterOrEqual(RemoteApiVersion.VERSION_1_23)) {
throw new SkipException("API version should be >= 1.23");
}

HostConfig hostConfig = new HostConfig().withPidsLimit(2L);
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(hostConfig.getPidsLimit()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.lang.reflect.Method;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -729,6 +728,28 @@ public void createContainerWithShmSize() throws DockerException {

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

assertEquals(inspectContainerResponse.getHostConfig().getShmSize(), hostConfig.getShmSize());
assertThat(inspectContainerResponse.getHostConfig().getShmSize(), is(hostConfig.getShmSize()));
}

@SuppressWarnings("Duplicates")
@Test
public void createContainerWithShmPidsLimit() throws DockerException {
final RemoteApiVersion apiVersion = getVersion(dockerClient);

if (!apiVersion.isGreaterOrEqual(RemoteApiVersion.VERSION_1_23)) {
throw new SkipException("API version should be >= 1.23");
}

HostConfig hostConfig = new HostConfig().withPidsLimit(2L);
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(hostConfig.getPidsLimit()));
}
}