testcontainers / testcontainers/testcontainers-java
Accessing containers from other containers and host by using the same hostname
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
Context
I have a Spring Boot application which uses Keycloak for it's identity management.
I would like to write an UI test which interacts with the application. As the application uses Keycloak the user is redirected to Keycloak in order to login at the first request. After logging in successfully, the user is redirected to the application.
Test setup
I have two containers (Keycloak and Browser). In order to get things working the browser (which runs in a container) needs to access the application (running on the host) and Keycloak (running in a different container).
Moreover, the host needs to access Keycloak using the same hostname as the browser container does...
I tried two approaches to relaize this:
Approach 1
The Browser Container accesses Keycloak using host.testcontainers.internal. This works fine, but unfortunately the host cannot resolve host.testcontainers.internal in order to access Keycloak.
Approach 2
I put the Browser container and the Keycloak container into a dedicated network. The result is almost the same, the host is not part of this network and therefore it cannot access Keycloak.
Conclusion
The most obvious solution might be to make host.testcontainers.internal resolvable from the host. Another option is that the host can participate in a certain network. Well, but maybe there are more ways to solve this...
Btw. using host.docker.internal (on Windows) all over the place works fine as this hostname is available within containers AND on the host.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the two networking approaches described in the issue and how Testcontainers handles hostname resolution between containers and the host. The work is done when the browser container and host can access Keycloak through the same hostname; the issue does not name a file or test to run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java, spring-boot
- Domain
- devops, networking, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100