testcontainers-go
testcontainers-go copied to clipboard
Do I have to specify the port for images with one port exposed?
# Dockerfile
EXPOSE 11211
CMD ["memcached"]
// Code
port := "11211/tcp"
rq := testcontainers.ContainerRequest{
Image: "memcached:1.6.10",
ExposedPorts: []string{port},
WaitingFor: wait.ForListeningPort(nat.Port(port)),
}
memcachedC, err := testcontainers.GenericContainer(context.Background(), testcontainers.GenericContainerRequest{
ContainerRequest: rq,
Started: true,
})
url, _ := memcachedC.Endpoint(context.Background(), "")
Is there any way to have the same functionality without specifying the port manually in a code?
I tried to make this work as well and eventually settled for parsing the image definition itself to discover the port
@slsyy Do you mean wait.ForListeningPort(nat.Port(port)) ?
What if several ports exposed?
I think we can close this one, as https://github.com/testcontainers/testcontainers-go/pull/468 was merged and released in v0.14.0, but please let us know if you need anything else here and feel free to reopen it.
Thanks for your time!