Use fixed ports in Dev Service for Keycloak on shared network & user request #28458
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes: #27763
When Docker host name isn't
localhost/127.0.0.1
, it's likely that exposed host port don't equal exposed container port. TestContainers are exposing random host port, fixed port is only exposed from the container's perspective. That's a good thing. There are only 2 situations we actually need fixed ports:I replaced usage of random fixed port for
sharedContainer
withuseSharedNetwork
as fixed port has no relation tosharedContainer
at all, I think it was a typo at first place introduced here #21999. Second thing I did is to use auto-detected host name and port for external calls only (test runner -> docker, e.g. when Dev Services for Keycloak are creating realm, users andKeycloakTestClient
is used inside tests). For internal communication (within shared network), random fixed port is still used as it's okay.As for tests, to my knowledge you can only test this when Docker endpoint isn't listening on localhost (e.g. remote Docker daemons). I run current test coverage related to Dev Services for Keycloak with local Docker engine and TestContainers Cloud (to verify host name != localhost scenarios). If you have suggestions on how this can be covered with IT, I'm happy to learn.
cc @geoand @sberyozkin