Skip to content
This repository was archived by the owner on Mar 21, 2022. It is now read-only.
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
27 changes: 25 additions & 2 deletions src/main/java/com/spotify/docker/client/messages/HostConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public class HostConfig {
private Boolean oomKillDisable;
@JsonProperty("OomScoreAdj")
private Integer oomScoreAdj;
@JsonProperty("AutoRemove")
private Boolean autoRemove;

private HostConfig() {
}
Expand Down Expand Up @@ -135,6 +137,7 @@ private HostConfig(final Builder builder) {
this.shmSize = builder.shmSize;
this.oomKillDisable = builder.oomKillDisable;
this.oomScoreAdj = builder.oomScoreAdj;
this.autoRemove = builder.autoRemove;
}

public List<String> binds() {
Expand Down Expand Up @@ -257,6 +260,10 @@ public Integer oomScoreAdj() {
return oomScoreAdj;
}

public Boolean autoRemove() {
return autoRemove;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand Down Expand Up @@ -296,7 +303,8 @@ public boolean equals(final Object o) {
Objects.equals(this.ipcMode, that.ipcMode) &&
Objects.equals(this.ulimits, that.ulimits) &&
Objects.equals(this.oomKillDisable, that.oomKillDisable) &&
Objects.equals(this.oomScoreAdj, that.oomScoreAdj);
Objects.equals(this.oomScoreAdj, that.oomScoreAdj) &&
Objects.equals(this.autoRemove, that.autoRemove);
}

@Override
Expand All @@ -306,7 +314,7 @@ public int hashCode() {
capDrop, networkMode, securityOpt, devices, memory, memorySwap,
memoryReservation, cpuShares, cpusetCpus, cpuQuota, cgroupParent,
restartPolicy, logConfig, ipcMode, ulimits, pidMode, shmSize,
oomKillDisable, oomScoreAdj);
oomKillDisable, oomScoreAdj, autoRemove);
}

@Override
Expand Down Expand Up @@ -343,6 +351,7 @@ public String toString() {
.add("shmSize", shmSize)
.add("oomKillDisable", oomKillDisable)
.add("oomScoreAdj", oomScoreAdj)
.add("autoRemove", autoRemove)
.toString();
}

Expand Down Expand Up @@ -501,6 +510,7 @@ public static class Builder {
private Long shmSize;
private Boolean oomKillDisable;
private Integer oomScoreAdj;
private Boolean autoRemove;

private Builder() {
}
Expand Down Expand Up @@ -537,6 +547,7 @@ private Builder(final HostConfig hostConfig) {
this.shmSize = hostConfig.shmSize;
this.oomKillDisable = hostConfig.oomKillDisable;
this.oomScoreAdj = hostConfig.oomScoreAdj;
this.autoRemove = hostConfig.autoRemove;
}

/**
Expand Down Expand Up @@ -1042,6 +1053,18 @@ public Integer oomScoreAdj() {
return oomScoreAdj;
}

public Boolean autoRemove() {
return autoRemove;
}

/**
* Only works for Docker API version >= 1.25.
*/
public Builder autoRemove(final Boolean autoRemove) {
this.autoRemove = autoRemove;
return this;
}

public HostConfig build() {
return new HostConfig(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3358,6 +3358,35 @@ public void testOomScoreAdj() throws Exception {
assertThat(info.hostConfig().oomScoreAdj(), is(500));
}

@Test(expected = ContainerNotFoundException.class)
public void testAutoRemoveWhenSetToTrue() throws Exception {
requireDockerApiVersionAtLeast("1.25", "AutoRemove");

// Container should be removed after it is stopped (new since API v.1.25)
// Pull image
sut.pull(BUSYBOX_LATEST);

final ContainerConfig config = ContainerConfig.builder()
.image(BUSYBOX_LATEST)
.hostConfig(HostConfig.builder()
.autoRemove(true) // Default is false
.build())
.build();

final ContainerCreation container = sut.createContainer(config, randomName());

sut.startContainer(container.id());

final ContainerInfo info = sut.inspectContainer(container.id());
assertThat(info.hostConfig().autoRemove(), is(true));
assertThat(info.state().running(), equalTo(true));

sut.stopContainer(container.id(), 5);

// A ContainerNotFoundException should be thrown since the container is removed when it stops
sut.inspectContainer(container.id());
}

@Test
public void testInspectSwarm() throws Exception {
requireDockerApiVersionAtLeast("1.24", "swarm support");
Expand Down