@@ -572,6 +572,29 @@ const container = await new GenericContainer("alpine")
572572const httpPort = container .getFirstMappedPort ();
573573```
574574
575+ Specify a protocol for the exposed port:
576+
577+ ``` javascript
578+ const container = await new GenericContainer (" alpine" )
579+ .withExposedPorts ({
580+ container: 80 ,
581+ protocol: " udp"
582+ })
583+ .start ();
584+ const httpPort = container .getMappedPort (80 , " udp" );
585+ ```
586+
587+ Alternatively, specify the protocol using a string with the format ` port/protocol ` :
588+
589+ ``` javascript
590+ const container = await new GenericContainer (" alpine" )
591+ .withExposedPorts (" 80/udp" )
592+ .start ();
593+ const httpPort = container .getMappedPort (" 80/udp" );
594+ ```
595+
596+ If no protocol is specified, it defaults to ` tcp ` .
597+
575598Specify fixed host port bindings (** not recommended** ):
576599
577600``` javascript
@@ -609,12 +632,12 @@ expect(response.status).toBe(200);
609632expect (await response .text ()).toBe (" PONG" );
610633```
611634
612- The example above starts a ` testcontainers/helloworld ` container and a ` socat ` container.
635+ The example above starts a ` testcontainers/helloworld ` container and a ` socat ` container.
613636The ` socat ` container is configured to forward traffic from port ` 8081 ` to the ` testcontainers/helloworld ` container on port ` 8080 ` .
614637
615638## Running commands
616639
617- To run a command inside an already started container, use the exec method.
640+ To run a command inside an already started container, use the exec method.
618641The command will be run in the container's working directory,
619642returning the combined output (` output ` ), standard output (` stdout ` ), standard error (` stderr ` ), and exit code (` exitCode ` ).
620643
0 commit comments