|
6 | 6 | import com.github.dockerjava.api.model.Bind; |
7 | 7 | import com.github.dockerjava.api.model.ContainerNetwork; |
8 | 8 | import com.github.dockerjava.api.model.ExposedPort; |
| 9 | +import com.github.dockerjava.api.model.HostConfig; |
9 | 10 | import com.github.dockerjava.api.model.Info; |
10 | 11 | import com.github.dockerjava.api.model.Link; |
11 | 12 | import com.github.dockerjava.api.model.PortBinding; |
@@ -153,6 +154,13 @@ public class GenericContainer<SELF extends GenericContainer<SELF>> |
153 | 154 | @Nullable |
154 | 155 | private String workingDirectory = null; |
155 | 156 |
|
| 157 | + /** |
| 158 | + * The shared memory size to use when starting the container. |
| 159 | + * This value is in bytes. |
| 160 | + */ |
| 161 | + @Nullable |
| 162 | + private Long shmSize; |
| 163 | + |
156 | 164 | private Map<MountableFile, String> copyToFileContainerPathMap = new HashMap<>(); |
157 | 165 |
|
158 | 166 | /* |
@@ -318,6 +326,17 @@ private void tryStart(Profiler profiler) { |
318 | 326 | } |
319 | 327 | } |
320 | 328 |
|
| 329 | + /** |
| 330 | + * Set any custom settings for the create command such as shared memory size. |
| 331 | + */ |
| 332 | + private HostConfig buildHostConfig() { |
| 333 | + HostConfig config = new HostConfig(); |
| 334 | + if (shmSize != null) { |
| 335 | + config.withShmSize(shmSize); |
| 336 | + } |
| 337 | + return config; |
| 338 | + } |
| 339 | + |
321 | 340 | private void connectToPortForwardingNetwork(String networkMode) { |
322 | 341 | PortForwardingContainer.INSTANCE.getNetwork().map(ContainerNetwork::getNetworkID).ifPresent(networkId -> { |
323 | 342 | if (!Arrays.asList(networkId, "none", "host").contains(networkMode)) { |
@@ -434,7 +453,9 @@ public Set<Integer> getLivenessCheckPortNumbers() { |
434 | 453 | } |
435 | 454 |
|
436 | 455 | private void applyConfiguration(CreateContainerCmd createCommand) { |
437 | | - |
| 456 | + HostConfig hostConfig = buildHostConfig(); |
| 457 | + createCommand.withHostConfig(hostConfig); |
| 458 | + |
438 | 459 | // Set up exposed ports (where there are no host port bindings defined) |
439 | 460 | ExposedPort[] portArray = exposedPorts.stream() |
440 | 461 | .map(ExposedPort::new) |
@@ -1157,6 +1178,16 @@ public SELF withCreateContainerCmdModifier(Consumer<CreateContainerCmd> modifier |
1157 | 1178 | return self(); |
1158 | 1179 | } |
1159 | 1180 |
|
| 1181 | + /** |
| 1182 | + * Size of /dev/shm |
| 1183 | + * @param bytes The number of megabytes to assign the shared memory. If null, it will apply the Docker default which is 64 MB. |
| 1184 | + * @return this |
| 1185 | + */ |
| 1186 | + public SELF withSharedMemorySize(Long bytes) { |
| 1187 | + this.shmSize = bytes; |
| 1188 | + return self(); |
| 1189 | + } |
| 1190 | + |
1160 | 1191 | /** |
1161 | 1192 | * Convenience class with access to non-public members of GenericContainer. |
1162 | 1193 | * |
|
0 commit comments