Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot define container hostname #883

Open
kyzooghost opened this issue Dec 16, 2024 · 1 comment
Open

Cannot define container hostname #883

kyzooghost opened this issue Dec 16, 2024 · 1 comment
Labels
triage Investigation required

Comments

@kyzooghost
Copy link

kyzooghost commented Dec 16, 2024

I would like to define the container hostname. This is available in the .NET and Java TestContainers frameworks, but not in the NodeJS framework

I understand this is a duplicate of #865 , however on reading the discussion there it is not clear to me what the rationale is for closing that issue :(

My specific use case is that I would like to set up a PostgreSQL container for integration testing in a TypeScript backend. Currently the container.getHost() method resolves to localhost and I am not clear how to change this for the PostgreSQL container. This is especially an issue when I need to orchestrate multiple TestContainers for the E2E tests, and the TypeScript backend app itself is using the localhost:... namespace already.

@kyzooghost
Copy link
Author

kyzooghost commented Dec 17, 2024

To give some further clarification on why customizing the container hostname is needed:

  • To configure a DbConnection for an ORM framework (Entity Framework, TypeORM), the host is a required parameter
  • It is ok to use localhost for the DbConnection host on my local machine - The ORM framework is running on the Docker host (my local machine), and the PostgreSQL container is running with an exposed port:
    • ORM framework will seek to connect to localhost: port
    • Docker host (my local machine) will receive this request
    • Because of port binding, Docker host can route this connection request to the PostgreSQL container
  • However if I run this in a CI pipeline or pod, then localhost may not be an available hostname on the Docker host (not my local machine anymore). Then the ORM framework will fail to connect to the PostgreSQL container running on TestContainers, and we have no available static config to facilitate the DbConnection

@cristianrgreco cristianrgreco added the triage Investigation required label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Investigation required
Projects
None yet
Development

No branches or pull requests

2 participants