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

PostgreSqlContainer cannot be reused without username/password #673

Closed
yukha-dw opened this issue Nov 14, 2023 · 1 comment
Closed

PostgreSqlContainer cannot be reused without username/password #673

yukha-dw opened this issue Nov 14, 2023 · 1 comment
Labels
triage Investigation required

Comments

@yukha-dw
Copy link

Because username and password are randomly generated, it's impossible to reuse the container when we don't specify them. In my case, i want to use unsafe parameter POSTGRES_HOST_AUTH_METHOD=trust, removing the needs of password. But when i tried to reuse it, testcontainers refused.

import { PostgreSqlContainer } from 'testcontainers';

export const createPostgresContainer = async () => {
  process.env.TESTCONTAINERS_RYUK_DISABLED = 'true';
  const postgresContainer = await new PostgreSqlContainer('postgis/postgis:16-3.4')
    .withName('place-postgres-testcontainer')
    .withEnvironment({ POSTGRES_HOST_AUTH_METHOD: 'trust' })
    .withDatabase('test')
    .withUsername('postgres')
    // .withPassword('p455w0r1ddd')
    .withReuse()
    .start();

  return postgresContainer;
};

export const stop = async () => {
  const postgresContainer = await createPostgresContainer();
  await postgresContainer.stop();
};

stop();
@cristianrgreco cristianrgreco added the bug Something isn't working label Nov 23, 2023
@cristianrgreco
Copy link
Collaborator

cristianrgreco commented Nov 23, 2023

Hi @yukha-dw, the username/password are hardcoded to test, not randomly generated.

Is there a reason you cannot use container.getUsername() / container.getPassword() and have to use POSTGRES_HOST_AUTH_METHOD=trust? If yes then this isn't supported without adding something like:

  const postgresContainer = await new PostgreSqlContainer('postgis/postgis:16-3.4')
    .withoutAuth()
    .start();

But this seems a very uncommon use case. You could extend the PostgresSqlContainer to fit your use case if needed.

@cristianrgreco cristianrgreco added triage Investigation required and removed bug Something isn't working labels Nov 23, 2023
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