Skip to content

Commit f2c8549

Browse files
committed
docs(wait): skipping external check when waiting for listening port, waiting for port mapping completion.
Signed-off-by: Marat Abrarov <[email protected]>
1 parent f5ab3e2 commit f2c8549

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

docs/features/wait/host_port.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,42 @@ req := ContainerRequest{
6060
WaitingFor: wait.ForExposedPort().SkipInternalCheck(),
6161
}
6262
```
63+
64+
## Skipping the external check
65+
66+
_Testcontainers for Go_ checks if the container is listening to the port externally (outside of container,
67+
from the host where _Testcontainers for Go_ is used) before returning the control to the caller.
68+
69+
But there are cases where this external check is not needed.
70+
In this case, the `wait.ForListeningPort.SkipExternalCheck` can be used to skip the external check.
71+
72+
```golang
73+
req := ContainerRequest{
74+
Image: "nginx:alpine",
75+
// Do not check port 80 externally, check it internally only
76+
WaitingFor: wait.ForListeningPort("80/tcp").SkipExternalCheck(),
77+
}
78+
```
79+
80+
If there is a need to wait only for completion of container port mapping (which doesn't happen immediately after container is started),
81+
then both internal and external checks can be skipped:
82+
83+
```golang
84+
req := ContainerRequest{
85+
Image: "nginx:alpine",
86+
ExposedPorts: []string{"80/tcp"},
87+
// Wait only for completion of port 80 mapping (from container runtime perspective), do not connect to 80 port
88+
WaitingFor: wait.ForListeningPort("80/tcp").SkipInternalCheck().SkipExternalCheck(),
89+
}
90+
```
91+
92+
Alternatively, `wait.ForMappedPort` can be used:
93+
94+
```golang
95+
req := ContainerRequest{
96+
Image: "nginx:alpine",
97+
ExposedPorts: []string{"80/tcp"},
98+
// Wait only for completion of port 80 mapping (from container runtime perspective), do not connect to 80 port
99+
WaitingFor: wait.ForMappedPort("80/tcp"),
100+
}
101+
```

0 commit comments

Comments
 (0)