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
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ public interface CreateContainerCmd extends SyncDockerCmd<CreateContainerRespons

CreateContainerCmd withCgroupParent(String cgroupParent);

CreateContainerCmd withGroupAdd(List<String> groups);

List<String> getGroupAdd();

/**
* Set the PID (Process) Namespace mode for the container, 'host': use the host's PID namespace inside the container
*/
Expand Down
19 changes: 19 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 @@ -200,6 +200,9 @@ public class HostConfig implements Serializable {
@JsonProperty("PidsLimit")
private Long pidsLimit;

@JsonProperty("GroupAdd")
private List<String> groupAdd;

/**
* @since ~{@link RemoteApiVersion#VERSION_1_30}
*/
Expand Down Expand Up @@ -826,6 +829,22 @@ public HostConfig withPidsLimit(Long pidsLimit) {
return this;
}

/**
* @see #groupAdd
*/
@CheckForNull
public List<String> getGroupAdd() {
return groupAdd;
}

/**
* @see #groupAdd
*/
public HostConfig withGroupAdd(List<String> groupAdd) {
this.groupAdd = groupAdd;
return this;
}

public HostConfig withRuntime(String runtime) {
this.runtime = runtime;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ public String[] getDnsSearch() {
return hostConfig.getDnsSearch();
}

@Override
@JsonIgnore
public List<String> getGroupAdd() {
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.

don't proxy host changes, keep only getter/setters in hostconfig

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Would that not make it awkward to use?
I saw several parts of hostconfig being proxied, is there a practice for which of them to expose?

return hostConfig.getGroupAdd();
}

@Override
public String getDomainName() {
return domainName;
Expand Down Expand Up @@ -1000,6 +1006,12 @@ public CreateContainerCmd withHostConfig(HostConfig hostConfig) {
return this;
}

@Override
public CreateContainerCmd withGroupAdd(List<String> groupAdd) {
this.hostConfig.withGroupAdd(groupAdd);
return this;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -835,6 +836,25 @@ public void createContainerWithNetworkID() {
assertThat(containerNetwork, notNullValue());
}

@Test
public void createContainerWithGroupAdd() throws DockerException {
List<String> groupsToAdd = Arrays.asList("www-data");

CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
.withGroupAdd(groupsToAdd)
.withCmd("true").exec();

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

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

InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

LOG.info("Inspect container {}", inspectContainerResponse.getHostConfig().getGroupAdd());

assertThat(inspectContainerResponse.getHostConfig().getGroupAdd(), is(groupsToAdd));
}

@Test
public void createContainerFromPrivateRegistryWithValidAuth() throws Exception {
DockerAssume.assumeSwarm(dockerRule.getClient());
Expand Down Expand Up @@ -865,5 +885,4 @@ public void createContainerFromPrivateRegistryWithNoAuth() throws Exception {
dockerRule.getClient().createContainerCmd(imgName)
.exec();
}

}