testcontainers / testcontainers/testcontainers-python
Docker in Docker on Mac requires to use host.docker.internal
オープン
まだ誰も着手していません。
👀 requires attention
📦 package: core
- 主要言語
- Python
- スター
- 2.3k
- フォーク
- 386
- 平均マージ
- 4時間 40分
- マージ済み PR(30日)
- 1
説明
I want to use a mongodb testcontainer within docker (to run in CI). When I use the testcontainer on the host, all works fine. However, when I use it inside docker, I need to access the testcontainer via the host (host.docker.internal). Is there some way for get_connection_url() to always return the "right" connection url?
I tried to put together an MWE:
docker run -v "/var/run/docker.sock":"/var/run/docker.sock" --privileged=true -it --entrypoint /bin/bash python:3.7.6
>> pip install testcontainers pymongo -q
>> python
import pymongo
from testcontainers.mongodb import MongoDbContainer
mongo = MongoDbContainer()
mongo.start()
print(mongo.get_connection_url())
# > 'mongodb://test:test@172.17.0.1:53859'
testcontainer_client = mongo.get_connection_client()
for db in testcontainer_client.list_databases(): print(db)
# > results in pymongo.errors.ServerSelectionTimeoutError
mongo_client = pymongo.MongoClient( 'mongodb://test:test@host.docker.internal:53859')
for db in mongo_client.list_databases(): print(db)
# > {'name': 'admin', 'sizeOnDisk': 102400, 'empty': False}
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず MongoDbContainer.get_connection_url() と get_connection_client() を追跡し、次に、示されているホストおよび Docker-in-Docker のケースで Docker ホストのアドレスがどのように決定されるかを調べます。issue の MongoDB の例を再現し、返された URL とクライアントがホスト上でも Docker 内でも動作することを検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- docker, mongodb, python
- 領域
- databases, devops, networking
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100