testcontainers / testcontainers/testcontainers-python

Bug: Not able to start basic example with Postgres with macos

Abierto
#802 15 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
2.3k
Forks
386
Merge medio
4 h 40 min
PR fusionados (30 d)
1

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Reproduce el ejemplo básico de PostgresContainer en macOS con Docker Desktop utilizando las versiones indicadas de Python, Docker y testcontainers. Empieza por PostgresContainer y la inicialización de DockerClient que se muestra en el traceback; después, sigue cómo se forma el host de Docker. Se considera terminado cuando el ejemplo se conecta correctamente sin el error de host tcp mal formado.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
docker, postgresql, python
Área
databases, devops, testing
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
52/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.