testcontainers / testcontainers/testcontainers-python

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

オープン
#802 コメント 15 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
2.3k
フォーク
386
平均マージ
4時間 40分
マージ済み PR(30日)
1

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

報告された Python、Docker、testcontainers のバージョンを使い、Docker Desktop 上の macOS で基本的な PostgresContainer の例を再現します。PostgresContainer と、traceback に示されている DockerClient の初期化から始め、Docker ホストがどのように形成されるかを追跡します。例が不正な tcp ホストエラーなしに正常に接続できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
docker, postgresql, python
領域
databases, devops, testing
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
52/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。