Skip to content

Commit bb63738

Browse files
author
Niklas Bolander
committed
Implement --group-add
1 parent fa04aed commit bb63738

4 files changed

Lines changed: 55 additions & 0 deletions

File tree

src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,10 @@ public interface CreateContainerCmd extends SyncDockerCmd<CreateContainerRespons
435435

436436
CreateContainerCmd withCgroupParent(String cgroupParent);
437437

438+
CreateContainerCmd withGroupAdd(String[] groups);
439+
440+
String[] getGroupAdd();
441+
438442
/**
439443
* Set the PID (Process) Namespace mode for the container, 'host': use the host's PID namespace inside the container
440444
*/

src/main/java/com/github/dockerjava/api/model/HostConfig.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ public class HostConfig implements Serializable {
200200
@JsonProperty("PidsLimit")
201201
private Long pidsLimit;
202202

203+
@JsonProperty("GroupAdd")
204+
private String[] groupAdd;
203205

204206
@JsonIgnore
205207
public Bind[] getBinds() {
@@ -816,6 +818,23 @@ public HostConfig withPidsLimit(Long pidsLimit) {
816818
this.pidsLimit = pidsLimit;
817819
return this;
818820
}
821+
822+
823+
/**
824+
* @see #groupAdd
825+
*/
826+
@CheckForNull
827+
public String[] getGroupAdd() {
828+
return groupAdd;
829+
}
830+
831+
/**
832+
* @see #groupAdd
833+
*/
834+
public HostConfig withGroupAdd(String[] groupAdd) {
835+
this.groupAdd = groupAdd;
836+
return this;
837+
}
819838
// end of auto-generated
820839

821840
@Override

src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ public String[] getDnsSearch() {
254254
return hostConfig.getDnsSearch();
255255
}
256256

257+
@Override
258+
@JsonIgnore
259+
public String[] getGroupAdd() {
260+
return hostConfig.getGroupAdd();
261+
}
262+
257263
@Override
258264
public String getDomainName() {
259265
return domainName;
@@ -987,6 +993,13 @@ public CreateContainerCmd withHostConfig(HostConfig hostConfig) {
987993
return this;
988994
}
989995

996+
@Override
997+
public CreateContainerCmd withGroupAdd(String[] groupAdd) {
998+
checkNotNull(groupAdd, "groupAdd was not specified");
999+
this.hostConfig.withGroupAdd(groupAdd);
1000+
return this;
1001+
}
1002+
9901003
@Override
9911004
public String toString() {
9921005
return ToStringBuilder.reflectionToString(this);

src/test/java/com/github/dockerjava/cmd/CreateContainerCmdIT.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,4 +823,23 @@ public void createContainerWithNetworkID() {
823823
}
824824
assertThat(containerNetwork, notNullValue());
825825
}
826+
827+
@Test
828+
public void createContainerWithGroupAdd() throws DockerException {
829+
String[] groupsToAdd = {"www-data"};
830+
831+
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
832+
.withGroupAdd(groupsToAdd)
833+
.withCmd("true").exec();
834+
835+
LOG.info("Created container {}", container.toString());
836+
837+
assertThat(container.getId(), not(isEmptyString()));
838+
839+
InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();
840+
841+
LOG.info("Inspect container {}", Arrays.toString(inspectContainerResponse.getHostConfig().getGroupAdd()));
842+
843+
assertThat(inspectContainerResponse.getHostConfig().getGroupAdd(), is(groupsToAdd));
844+
}
826845
}

0 commit comments

Comments
 (0)