Skip to content

Commit 5050db6

Browse files
committed
Add documentation for specifying ports
1 parent e307558 commit 5050db6

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

docs/features/containers.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,29 @@ const container = await new GenericContainer("alpine")
572572
const 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+
575598
Specify fixed host port bindings (**not recommended**):
576599

577600
```javascript
@@ -609,12 +632,12 @@ expect(response.status).toBe(200);
609632
expect(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.
613636
The `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.
618641
The command will be run in the container's working directory,
619642
returning the combined output (`output`), standard output (`stdout`), standard error (`stderr`), and exit code (`exitCode`).
620643

0 commit comments

Comments
 (0)