Testcontainers is a NodeJS library that supports tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
Expected Behaviour
When a container is part of multiple networks, I should be able to consistently get the right port using getMappedPort.
Actual Behaviour
In these conditions, getMappedPort intermittently returns a port different to that in the Ports block of NetworkSettings, leading to clients using that port to fail to connect to their destination.
Steps to Reproduce
I have created a small repository here to reproduce the issue.
There's a ReadMe included with the necessary instructions to run the project and see the issue (note that it's intermittent, so you might need to run it more than once)
Environment Information
I am seeing this in multiple environments (mac & windows)
❯ npm doctor
Connecting to the registry
Ok
Checking npm version
Ok
current: v10.9.0, latest: v10.9.0
Checking node version
Ok
current: v22.11.0, recommended: v22.11.0
Checking configured npm registry
Ok
using default registry (https://registry.npmjs.org/)
Checking for git executable in PATH
Ok
/usr/bin/git
Checking for global bin folder in PATH
Ok
/Users/liam/.nvm/versions/node/v22.11.0/bin
Checking permissions on cached files (this may take awhile)
Ok
Checking permissions on local node_modules (this may take awhile)
Ok
Checking permissions on global node_modules (this may take awhile)
Ok
Checking permissions on local bin folder
Ok
Checking permissions on global bin folder
Ok
Verifying cache contents (this may take awhile)
npm warn doctor verifyCachedFiles Content garbage-collected: 58 (106816249 bytes)
npm warn doctor verifyCachedFiles Cache issues have been fixed
Ok
verified 1970 tarballs
Expected Behaviour When a container is part of multiple networks, I should be able to consistently get the right port using
getMappedPort
.Actual Behaviour In these conditions,
getMappedPort
intermittently returns a port different to that in thePorts
block ofNetworkSettings
, leading to clients using that port to fail to connect to their destination.Testcontainer Logs Logs of the failing run:
Steps to Reproduce I have created a small repository here to reproduce the issue. There's a ReadMe included with the necessary instructions to run the project and see the issue (note that it's intermittent, so you might need to run it more than once)
Environment Information I am seeing this in multiple environments (mac & windows)
Mac Information
npm doctor: