Skip to content

Commit 39413b5

Browse files
committed
Export SocatContainer, StartedSocatContainer and add docs
1 parent a4cec40 commit 39413b5

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

docs/features/containers.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,27 @@ const container = await new GenericContainer("alpine")
583583
.start();
584584
```
585585

586+
## SocatContainer as a TCP proxy
587+
588+
`SocatContainer` enables any TCP port of another container to be exposed publicly.
589+
590+
```javascript
591+
const network = await new Network().start();
592+
593+
const helloworld = await new GenericContainer("testcontainers/helloworld:1.2.0")
594+
.withExposedPorts(8080)
595+
.withNetwork(network)
596+
.withNetworkAliases("helloworld")
597+
.start();
598+
599+
const socat = await new SocatContainer().withNetwork(network).withTarget(8081, "helloworld", 8080).start();
600+
601+
const socatUrl = `http://${socat.getHost()}:${socat.getMappedPort(8081)}`;
602+
```
603+
604+
The example above starts a `testcontainers/helloworld` container and a `socat` container.
605+
The `socat` container is configured to forward traffic from port `8081` to the `testcontainers/helloworld` container on port `8080`.
606+
586607
## Running commands
587608

588609
To run a command inside an already started container, use the exec method.

packages/testcontainers/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,5 @@ export type NetworkSettings = {
104104
networkId: string;
105105
ipAddress: string;
106106
};
107+
108+
export { SocatContainer, StartedSocatContainer } from "./socat/socat-container";

0 commit comments

Comments
 (0)