Bug: Not able to start basic example with Postgres with macos
Describe the bug
I'm trying to run the basic example that appears in the documentation in macos Sequoia 15.4 with M2 chip and testcontainers is not able to connect to docker engine due to incorrect host.
To Reproduce
Python 3.12.6 (v3.12.6:a4a2d2b0d85, Sep 6 2024, 16:08:03) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> with PostgresContainer("postgres:16") as postgres:
... psql_url = postgres.get_connection_url()
... engine = sqlalchemy.create_engine(psql_url)
... with engine.begin() as connection:
... version, = connection.execute(sqlalchemy.text("SELECT version()")).fetchone()
...
KeyboardInterrupt
>>>
KeyboardInterrupt
>>> from testcontainers.postgres import PostgresContainer
>>> import sqlalchemy
>>> with PostgresContainer("postgres:16") as postgres:
... psql_url = postgres.get_connection_url()
... engine = sqlalchemy.create_engine(psql_url)
... with engine.begin() as connection:
... version, = connection.execute(sqlalchemy.text("SELECT version()")).fetchone()
...
using host tcp\://127.0.0.1\:49693
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ves/Projects/game-api/.venv/lib/python3.12/site-packages/testcontainers/postgres/__init__.py", line 59, in __init__
super().__init__(image=image, **kwargs)
File "/Users/ves/Projects/game-api/.venv/lib/python3.12/site-packages/testcontainers/core/container.py", line 50, in __init__
self._docker = DockerClient(**(docker_client_kw or {}))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ves/Projects/game-api/.venv/lib/python3.12/site-packages/testcontainers/core/docker_client.py", line 68, in __init__
self.client = docker.from_env(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ves/Projects/game-api/.venv/lib/python3.12/site-packages/docker/client.py", line 94, in from_env
return cls(
^^^^
File "/Users/ves/Projects/game-api/.venv/lib/python3.12/site-packages/docker/client.py", line 45, in __init__
self.api = APIClient(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ves/Projects/game-api/.venv/lib/python3.12/site-packages/docker/api/client.py", line 146, in __init__
base_url = utils.parse_host(
^^^^^^^^^^^^^^^^^
File "/Users/ves/Projects/game-api/.venv/lib/python3.12/site-packages/docker/utils/utils.py", line 296, in parse_host
raise errors.DockerException(
docker.errors.DockerException: Invalid bind address format: port is required: tcp\://127.0.0.1\:49693
Runtime environment
Provide a summary of your runtime environment. Which operating system, python version, and docker version are you using? What is the version of testcontainers-python you are using? You can run the following commands to get the relevant information.
# Get the operating system information (on a unix os).
$ uname -a
Darwin NB230915VES 24.4.0 Darwin Kernel Version 24.4.0: Wed Mar 19 21:17:25 PDT 2025; root:xnu-11417.101.15~1/RELEASE_ARM64_T6020 arm64
# Get the python version.
$ python --version
Python 3.12.6
# Get the docker version and other docker information.
$ docker info
docker info
Client:
Version: 28.0.4
Context: desktop-linux
Debug Mode: false
Plugins:
ai: Docker AI Agent - Ask Gordon (Docker Inc.)
Version: v1.1.3
Path: /Users/ves/.docker/cli-plugins/docker-ai
buildx: Docker Buildx (Docker Inc.)
Version: v0.22.0-desktop.1
Path: /Users/ves/.docker/cli-plugins/docker-buildx
cloud: Docker Cloud (Docker Inc.)
Version: 0.2.20
Path: /Users/ves/.docker/cli-plugins/docker-cloud
compose: Docker Compose (Docker Inc.)
Version: v2.34.0-desktop.1
Path: /Users/ves/.docker/cli-plugins/docker-compose
debug: Get a shell into any image or container (Docker Inc.)
Version: 0.0.38
Path: /Users/ves/.docker/cli-plugins/docker-debug
desktop: Docker Desktop commands (Beta) (Docker Inc.)
Version: v0.1.6
Path: /Users/ves/.docker/cli-plugins/docker-desktop
dev: Docker Dev Environments (Docker Inc.)
Version: v0.1.2
Path: /Users/ves/.docker/cli-plugins/docker-dev
extension: Manages Docker extensions (Docker Inc.)
Version: v0.2.27
Path: /Users/ves/.docker/cli-plugins/docker-extension
init: Creates Docker-related starter files for your project (Docker Inc.)
Version: v1.4.0
Path: /Users/ves/.docker/cli-plugins/docker-init
model: Docker Model Runner (Docker Inc.)
Version: v0.1.4
Path: /Users/ves/.docker/cli-plugins/docker-model
sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
Version: 0.6.0
Path: /Users/ves/.docker/cli-plugins/docker-sbom
scout: Docker Scout (Docker Inc.)
Version: v1.17.0
Path: /Users/ves/.docker/cli-plugins/docker-scout
WARNING: Plugin "/Users/ves/.docker/cli-plugins/docker-feedback" is not valid: failed to fetch metadata: fork/exec /Users/ves/.docker/cli-plugins/docker-feedback: no such file or directory
Server:
Containers: 2
Running: 0
Paused: 0
Stopped: 2
Images: 104
Server Version: 28.0.4
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
CDI spec directories:
/etc/cdi
/var/run/cdi
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 753481ec61c7c8955a23d6ff7bc8e4daed455734
runc version: v1.2.5-0-g59923ef
init version: de40ad0
Security Options:
seccomp
Profile: unconfined
cgroupns
Kernel Version: 6.10.14-linuxkit
Operating System: Docker Desktop
OSType: linux
Architecture: aarch64
CPUs: 12
Total Memory: 7.653GiB
Name: docker-desktop
ID: ************************************
Docker Root Dir: /var/lib/docker
Debug Mode: false
HTTP Proxy: http.docker.internal:3128
HTTPS Proxy: http.docker.internal:3128
No Proxy: hubproxy.docker.internal
Labels:
com.docker.desktop.address=unix:///Users/ves/Library/Containers/com.docker.docker/Data/docker-cli.sock
Experimental: false
Insecure Registries:
hubproxy.docker.internal:5555
::1/128
*********/8
Live Restore Enabled: false
WARNING: DOCKER_INSECURE_NO_IPTABLES_RAW is set
WARNING: daemon is not using the default seccomp profile
# Get all python packages.
$ pip freeze
alembic==1.15.2
blinker==1.9.0
certifi==2025.1.31
charset-normalizer==3.4.1
click==8.1.8
dependency-injector==4.42.0
docker==7.1.0
dotenv==0.9.9
Flask==3.1.0
flask-marshmallow==1.3.0
Flask-Migrate==4.1.0
Flask-SQLAlchemy==3.1.1
idna==3.10
iniconfig==2.1.0
itsdangerous==2.2.0
Jinja2==3.1.6
Mako==1.3.9
MarkupSafe==3.0.2
marshmallow==3.26.1
marshmallow-sqlalchemy==1.4.1
packaging==24.2
pluggy==1.5.0
psycopg2-binary==2.9.10
pytest==8.3.5
python-dotenv==1.1.0
requests==2.32.3
ruff==0.11.2
six==1.16.0
SQLAlchemy==2.0.40
testcontainers==4.10.0
typing_extensions==4.13.0
urllib3==2.3.0
Werkzeug==3.1.3
wrapt==1.17.2
reproducer:
mkdir issue-802 && cd $_ && python -m venv .venv && . $_/bin/activate && pip install testcontainers[postgres] sqlalchemy psycopg2-binary
script.py:
from testcontainers.postgres import PostgresContainer
import sqlalchemy
with PostgresContainer("postgres:16-alpine") as postgres:
psql_url = postgres.get_connection_url()
engine = sqlalchemy.create_engine(psql_url)
with engine.begin() as connection:
version, = connection.execute(sqlalchemy.text("SELECT version()")).fetchone()
print(f"version: {version}")
output:
$ python script.py
using host tcp://127.0.0.1:49198
using host tcp://127.0.0.1:49198
Pulling image testcontainers/ryuk:0.8.1
Container started: 479d1613f6ff
Waiting for container <Container: 479d1613f6ff> with image testcontainers/ryuk:0.8.1 to be ready ...
Pulling image postgres:16-alpine
Container started: 4c3b35cc1e5d
Waiting for container <Container: 4c3b35cc1e5d> with image postgres:16-alpine to be ready ...
Waiting for container <Container: 4c3b35cc1e5d> with image postgres:16-alpine to be ready ...
version: PostgreSQL 16.4 on aarch64-unknown-linux-musl, compiled by gcc (Alpine 13.2.1_git20240309) 13.2.1 20240309, 64-bit
@alexanderankin I have tried your reproducer and I get the same error:
python script.py
using host tcp\://127.0.0.1\:49693
Traceback (most recent call last):
File "/Users/ves/Projects/issue-802/script.py", line 3, in <module>
with PostgresContainer("postgres:16-alpine") as postgres:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ves/Projects/issue-802/.venv/lib/python3.12/site-packages/testcontainers/postgres/__init__.py", line 59, in __init__
super().__init__(image=image, **kwargs)
File "/Users/ves/Projects/issue-802/.venv/lib/python3.12/site-packages/testcontainers/core/container.py", line 50, in __init__
self._docker = DockerClient(**(docker_client_kw or {}))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ves/Projects/issue-802/.venv/lib/python3.12/site-packages/testcontainers/core/docker_client.py", line 68, in __init__
self.client = docker.from_env(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ves/Projects/issue-802/.venv/lib/python3.12/site-packages/docker/client.py", line 94, in from_env
return cls(
^^^^
File "/Users/ves/Projects/issue-802/.venv/lib/python3.12/site-packages/docker/client.py", line 45, in __init__
self.api = APIClient(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ves/Projects/issue-802/.venv/lib/python3.12/site-packages/docker/api/client.py", line 146, in __init__
base_url = utils.parse_host(
^^^^^^^^^^^^^^^^^
File "/Users/ves/Projects/issue-802/.venv/lib/python3.12/site-packages/docker/utils/utils.py", line 296, in parse_host
raise errors.DockerException(
docker.errors.DockerException: Invalid bind address format: port is required: tcp\://127.0.0.1\:49693
I'm using testcontainers for Java in another project and it's working, so it shouldn't be something configured on my machine.
Any idea of what could be? It's also strange that the docker host uses some backlash to escape :.
Thanks!
breaks with docker server version 28? I'm on 27.... but its not the first time something working in java doesn't work in python, I'm coming from java world trying to help out with python version. I will try to do some more digging when i have better internet, i currently cant reproduce
I have downgraded to Docker engine 27.5.1 and still the same. Let me know if you need more details about my setup
is it significantly different from https://docs.docker.com/desktop/setup/install/mac-install/ ? I think this is what I did because it does not show up in "brew leaves"
I have installed exactly that and it's not working... don't know why
see if this fixes it?
pip install git+https://github.com/testcontainers/testcontainers-python.git@fix/802-bad-properties-parsing
if it does I might add more warning level logging to see who this fix breaks, as it deals with testcontainers desktop.
alternatively, if i can remember how to produce this file, i might test with configparser or try to manually port the properties parser from java into this project as that could be producing the exceptions? still have to test...
Sadly not, still getting the same error.
python script.py
using host tcp\://127.0.0.1\:49693
Traceback (most recent call last):
File "/Users/ves/Projects/issue-802/script.py", line 3, in <module>
with PostgresContainer("postgres:16-alpine") as postgres:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ves/Projects/issue-802/.venv/lib/python3.12/site-packages/testcontainers/postgres/__init__.py", line 59, in __init__
super().__init__(image=image, **kwargs)
File "/Users/ves/Projects/issue-802/.venv/lib/python3.12/site-packages/testcontainers/core/container.py", line 50, in __init__
self._docker = DockerClient(**(docker_client_kw or {}))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ves/Projects/issue-802/.venv/lib/python3.12/site-packages/testcontainers/core/docker_client.py", line 68, in __init__
self.client = docker.from_env(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ves/Projects/issue-802/.venv/lib/python3.12/site-packages/docker/client.py", line 94, in from_env
return cls(
^^^^
File "/Users/ves/Projects/issue-802/.venv/lib/python3.12/site-packages/docker/client.py", line 45, in __init__
self.api = APIClient(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ves/Projects/issue-802/.venv/lib/python3.12/site-packages/docker/api/client.py", line 146, in __init__
base_url = utils.parse_host(
^^^^^^^^^^^^^^^^^
File "/Users/ves/Projects/issue-802/.venv/lib/python3.12/site-packages/docker/utils/utils.py", line 296, in parse_host
raise errors.DockerException(
docker.errors.DockerException: Invalid bind address format: port is required: tcp\://127.0.0.1\:49693
Looks indeed still like a parsing error and I think I have seen those in the past.
@vistiyos Can you please share the content of your ~/.testcontainers.properties file?
This is the content of the file:
#Modified by Testcontainers
#Mon Jan 15 11:51:07 CET 2024
docker.client.strategy=org.testcontainers.dockerclient.UnixSocketClientProviderStrategy
tc.host=tcp\://127.0.0.1\:49693
testcontainers.reuse.enable=true
docker.host=tcp\://127.0.0.1\:49693
It seems the parsing error is coming from here.
Yeah this looks a bit like maybe old Testcontainers Cloud values?
The easiest solution:
Just delete the tc.host and docker.host lines 🙂
Are you using Testcontainers Cloud or Testcontainers Desktop?
After removing those lines it worked! Thank you so much both for your help!! @kiview @alexanderankin
I was using Testcontainers Desktop in the past but no anymore.
Maybe adding this as a warning for people that has used it for them to check? If you don't consider this necessary, I can just close it as solved
lets leave open for now, I would like to implement+test a fix
Using the same reproducer I get:
Pulling image testcontainers/ryuk:0.8.1
Container started: 5ea5d5c579d7
Waiting for container <Container: 5ea5d5c579d7> with image testcontainers/ryuk:0.8.1 to be ready ...
Pulling image postgres:16-alpine
Container started: 4652589cc8a6
Waiting for container <Container: 4652589cc8a6> with image postgres:16-alpine to be ready ...
Waiting for container <Container: 4652589cc8a6> with image postgres:16-alpine to be ready ...
Traceback (most recent call last):
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 145, in __init__
self._dbapi_connection = engine.raw_connection()
~~~~~~~~~~~~~~~~~~~~~^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 3297, in raw_connection
return self.pool.connect()
~~~~~~~~~~~~~~~~~^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py", line 449, in connect
return _ConnectionFairy._checkout(self)
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py", line 1264, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py", line 713, in checkout
rec = pool._do_get()
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get
with util.safe_reraise():
~~~~~~~~~~~~~~~~~^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py", line 224, in __exit__
raise exc_value.with_traceback(exc_tb)
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get
return self._create_connection()
~~~~~~~~~~~~~~~~~~~~~~~^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection
return _ConnectionRecord(self)
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py", line 675, in __init__
self.__connect()
~~~~~~~~~~~~~~^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py", line 901, in __connect
with util.safe_reraise():
~~~~~~~~~~~~~~~~~^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py", line 224, in __exit__
raise exc_value.with_traceback(exc_tb)
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py", line 897, in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/engine/create.py", line 646, in connect
return dialect.connect(*cargs, **cparams)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/engine/default.py", line 625, in connect
return self.loaded_dbapi.connect(*cargs, **cparams) # type: ignore[no-any-return] # NOQA: E501
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: connection to server at "127.0.0.1", port 32995 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/script.py", line 7, in <module>
with engine.begin() as connection:
~~~~~~~~~~~~^^
File "/opt/homebrew/Cellar/[email protected]/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/contextlib.py", line 141, in __enter__
return next(self.gen)
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 3237, in begin
with self.connect() as conn:
~~~~~~~~~~~~^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 3273, in connect
return self._connection_cls(self)
~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 147, in __init__
Connection._handle_dbapi_exception_noconnection(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
err, dialect, engine
^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 2436, in _handle_dbapi_exception_noconnection
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 145, in __init__
self._dbapi_connection = engine.raw_connection()
~~~~~~~~~~~~~~~~~~~~~^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 3297, in raw_connection
return self.pool.connect()
~~~~~~~~~~~~~~~~~^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py", line 449, in connect
return _ConnectionFairy._checkout(self)
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py", line 1264, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py", line 713, in checkout
rec = pool._do_get()
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get
with util.safe_reraise():
~~~~~~~~~~~~~~~~~^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py", line 224, in __exit__
raise exc_value.with_traceback(exc_tb)
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get
return self._create_connection()
~~~~~~~~~~~~~~~~~~~~~~~^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection
return _ConnectionRecord(self)
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py", line 675, in __init__
self.__connect()
~~~~~~~~~~~~~~^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py", line 901, in __connect
with util.safe_reraise():
~~~~~~~~~~~~~~~~~^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py", line 224, in __exit__
raise exc_value.with_traceback(exc_tb)
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py", line 897, in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/engine/create.py", line 646, in connect
return dialect.connect(*cargs, **cparams)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/sqlalchemy/engine/default.py", line 625, in connect
return self.loaded_dbapi.connect(*cargs, **cparams) # type: ignore[no-any-return] # NOQA: E501
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "/Users/krystian.kulgawczuk/dev/temp/issue-802/issue-802/.venv/lib/python3.13/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at "127.0.0.1", port 32995 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
(Background on this error at: https://sqlalche.me/e/20/e3q8)
# os
Darwin M-QG6T9WDHR4 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000 arm64
# python
Python 3.13.3
# docker
Client: Docker Engine - Community
Version: 28.2.2
Context: colima
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.13.1
Path: /Users/krystian.kulgawczuk/.docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: 2.24.7
Path: /Users/krystian.kulgawczuk/.docker/cli-plugins/docker-compose
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 151
Server Version: 27.4.0
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 88bf19b2105c8b17560993bee28a01ddc2f97182
runc version: v1.2.2-0-g7cb3632
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
cgroupns
Kernel Version: 6.8.0-50-generic
Operating System: Ubuntu 24.04.1 LTS
OSType: linux
Architecture: aarch64
CPUs: 2
Total Memory: 1.914GiB
Name: colima
ID: e80dcb10-8dea-452b-8fcb-758a7d31fc1d
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
I have no .testcontainers.properties file.
Works fine when I put time.sleep(2) right after with PostgresContainer("postgres:16-alpine") as postgres: