testcontainers-go icon indicating copy to clipboard operation
testcontainers-go copied to clipboard

Do I have to specify the port for images with one port exposed?

Open slsyy opened this issue 4 years ago • 2 comments

# 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?

slsyy avatar Aug 12 '21 09:08 slsyy

I tried to make this work as well and eventually settled for parsing the image definition itself to discover the port

ajbouh avatar Apr 28 '22 20:04 ajbouh

@slsyy Do you mean wait.ForListeningPort(nat.Port(port)) ?

What if several ports exposed?

fiftin avatar Jun 17 '22 19:06 fiftin

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!

mdelapenya avatar Sep 16 '22 09:09 mdelapenya