Skip to content

Commit c085fb2

Browse files
Implement providing IPC mode (#196)
1 parent 75a35d1 commit c085fb2

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ const container = await new GenericContainer("alpine")
281281
.start();
282282
```
283283

284+
Creating a container with [IPC mode](https://docs.docker.com/engine/reference/run/#ipc-settings---ipc):
285+
286+
```javascript
287+
const { GenericContainer } = require("testcontainers");
288+
289+
const container = await new GenericContainer("alpine")
290+
.withIpcMode("host")
291+
.start();
292+
```
293+
284294
Testcontainers will not wait for a container to stop, to override:
285295

286296
```javascript

src/docker-client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ type CreateOptions = {
8989
privilegedMode: boolean;
9090
autoRemove: boolean;
9191
extraHosts: ExtraHost[];
92+
ipcMode?: string;
9293
};
9394

9495
export type CreateNetworkOptions = {
@@ -147,6 +148,7 @@ export class DockerodeClient implements DockerClient {
147148
// @ts-ignore
148149
Healthcheck: this.getHealthCheck(options.healthCheck),
149150
HostConfig: {
151+
IpcMode: options.ipcMode,
150152
ExtraHosts: this.getExtraHosts(options.extraHosts),
151153
AutoRemove: options.autoRemove,
152154
NetworkMode: options.networkMode,

src/generic-container.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,19 @@ describe("GenericContainer", () => {
253253
await container.stop();
254254
});
255255

256+
it("should set the IPC mode", async () => {
257+
const container = await new GenericContainer("cristianrgreco/testcontainer:1.1.12")
258+
.withIpcMode("host")
259+
.withExposedPorts(8080)
260+
.start();
261+
262+
const url = `http://${container.getHost()}:${container.getMappedPort(8080)}`;
263+
const response = await fetch(`${url}/hello-world`);
264+
265+
expect(response.status).toBe(200);
266+
await container.stop();
267+
});
268+
256269
it("should stop the container when the host port check wait strategy times out", async () => {
257270
const containerName = `container-${new RandomUuid().nextUuid()}`;
258271

src/generic-container.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export class GenericContainer implements TestContainer {
8989
protected useDefaultLogDriver = false;
9090
protected privilegedMode = false;
9191
protected daemonMode = false;
92+
protected ipcMode?: string;
9293
protected pullPolicy: PullPolicy = new DefaultPullPolicy();
9394
protected tarToCopy?: archiver.Archiver;
9495

@@ -135,6 +136,7 @@ export class GenericContainer implements TestContainer {
135136
privilegedMode: this.privilegedMode,
136137
autoRemove: this.daemonMode,
137138
extraHosts: this.extraHosts,
139+
ipcMode: this.ipcMode,
138140
});
139141

140142
if (!this.dockerImageName.isHelperContainer() && PortForwarderInstance.isRunning()) {
@@ -246,6 +248,11 @@ export class GenericContainer implements TestContainer {
246248
return this;
247249
}
248250

251+
public withIpcMode(ipcMode: string): this {
252+
this.ipcMode = ipcMode;
253+
return this;
254+
}
255+
249256
public withCopyFileToContainer(sourcePath: string, containerPath: string): this {
250257
this.getTarToCopy().file(sourcePath, { name: containerPath });
251258
return this;

0 commit comments

Comments
 (0)