-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ToHostPort needs more flexibility #107
Comments
Hi https://www.testcontainers.org/features/networking/ ok nvm. I can just let docker select a host port binding... and get what port it used to avoid port collisions "This is to always resolve to a working ip and port to communicate with the docker container. It is also possible to map a random port, i.e. let Docker choose a available port. For example:" |
Hi @ta32, the current implementation will use the docker ability to select a random port on the host (where daemon hosting the container). In e.g. unittest public void ImplicitPortMappingShouldWork()
{
using (
var container =
Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
.Build()
.Start())
{
var endpoint = container.ToHostExposedEndpoint("5432/tcp");
AreNotEqual(0, endpoint.Port);
}
} will render the following C:\Users\martoffi>docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
93289c5d2b57 postgres:9.6-alpine "docker-entrypoint.s…" 36 seconds ago Up 29 seconds 0.0.0.0:32768->5432/tcp amazing_keller where the If you want to have explicit portmapping, look at the unittest public void ExplicitPortMappingShouldWork()
{
using (
var container =
Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(40001, 5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
.Build()
.Start())
{
var endpoint = container.ToHostExposedEndpoint("5432/tcp");
AreEqual(40001, endpoint.Port);
}
} Where the container port 5432 is exposed on host 40001 and thus may experience a conflict. This issue is in regards when custom networking or other remote daemon. Therefore the Cheers, |
Finally support for a custom resolver on single containers. |
The current implementation how to get a host and port, the host part is not sufficient in some cases to acommodate users. It needs to have a bit of a configurable flexibility. This is derived from Issue #105.
The current implementation is merely a bulldozer as follows:
The text was updated successfully, but these errors were encountered: