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
Bug: Postgres Port not working #569
Comments
I think you are setting the port inside the container not outside. There is
a separate API for what you are trying to do.
…On Fri, May 10, 2024, 3:47 PM David Horvát ***@***.***> wrote:
*Describe the bug*
Creating a PostgresContainer gets stuck on creating when port= is defined
and raises a Runtime error after 1-2 minutes except when setting to the
default Postgres port 5432.
Not defining it leads to random port mapping (as intended), but reading it
with PostgresContainer.port returns the default Postgres port instead of
the randomly selected one. It gets correctly mapped in the connection url
though.
*To Reproduce*
import ...
pytest_plugins = ('pytest_asyncio',)
# Gets stuck in creating container process and raises a RuntimeException ***@***.*** def test_postgres_start(monkeypatch):
port = 3182
with PostgresContainer(
"postgres:16-alpine",
port=port,
) as pg:
...
# Reading port via .port returns the default port and not the actual ***@***.*** def test_postgres_port(monkeypatch):
# Gets stuck in creating process:
with PostgresContainer(
"postgres:16-alpine"
) as pg:
port = pg.get_connection_url().split(":")[-1].split('/')[0]
assert port != pg.port
You can check the port with nmap as-well to be certain that the variable
fails.
Setting driver=None leads to the same results.
*Runtime environment*
Versions and specs (at time of creating latest stable versions):
- Machine: EndeavourOS Linux 6.8.9-arch1-2 x86_64 GNU/Linux
- Docker: v26.1.2
- Python: v3.12.3
- pip: v24.0
- pytest: v8.2.0
- pytest-asyncio: v0.23.6
- asyncpg: v0.29.0
- testcontainers: v4.4.0
—
Reply to this email directly, view it on GitHub
<#569>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACECGJFH7DB4VBFIA4F3JXLZBUP6NAVCNFSM6AAAAABHRFCYL6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGI4TAMZRG4YDINQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Hello! |
you can get the exposed port using this function: https://github.com/testcontainers/testcontainers-python/blob/main/core/testcontainers/core/container.py#L140 testcontainers-python/core/testcontainers/core/container.py Lines 139 to 148 in 690b9b4
e.g. by:
|
documentation can be improved a lot, you are right about that |
okay, that works too, thanks 👍 |
Describe the bug
Creating a
PostgresContainer
gets stuck on creating whenport=
is defined and raises a Runtime error after 1-2 minutes except when setting to the default Postgres port 5432.Not defining it leads to random port mapping (as intended), but reading it with
PostgresContainer.port
returns the default Postgres port instead of the randomly selected one. It gets correctly mapped in the connection url though.To Reproduce
You can check the port with
nmap
as-well to be certain that the variable fails.Setting
driver=None
leads to the same results.Runtime environment
Versions and specs (at time of creating latest stable versions):
The text was updated successfully, but these errors were encountered: