File tree Expand file tree Collapse file tree
packages/testcontainers/src Expand file tree Collapse file tree Original file line number Diff line number Diff 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
588609To run a command inside an already started container, use the exec method.
Original file line number Diff line number Diff 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" ;
You can’t perform that action at this time.
0 commit comments