testcontainers / testcontainers/testcontainers-python
mongodb testcontainers cannot run in GitLab - while postgres can
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 2.3k
- 派生
- 386
- 平均合并
- 4 小时 40 分钟
- 30 天内合并 PR
- 1
描述
Describe the bug
Launching MongoDB Testcontainer in GitLab with dind yields error: "Exception: port mapping for container xxxx and port 27017 is not available" - i.e.:
"testcontainers.core.exceptions.TimeoutException: Wait time (120s) exceeded for get_exposed_port(args: (27017,), kwargs {}). Exception: port mapping for container afa0edc97197698ae51ad40d64a8f2b37de2a52027d3cb9f4c9e9959442a9b8d and port 27017 is not available"
Expected test to run as it does in the local test with docker.
Tried running the postgres testcontainer in the same test file and pipeline, which works. So am suspecting an issue with the mongodb testcontainer implementation.
To Reproduce
Add the test from here:
https://github.com/testcontainers/testcontainers-python/blob/928af5a88393d8223a0d5a55e9378941826997ec/mongodb/tests/test_mongodb.py#L57
And the postgres test which works from here:
https://testcontainers-python.readthedocs.io/en/latest/postgres/README.html
And run in GitLab pipeline with:
.test:
services:
- name: docker:dind
command: ["--tls=false"]
variables:
DOCKER_HOST: "tcp://docker:2375"
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
image: python:3.12.0-slim-bookworm
script:
- python -m pip install poetry
- poetry install --with dev
- poetry run pytest .
Runtime environment
Running GitLab Community version 16.4.0 with GitLab runners and docker in docker.
Testcontainers version 3.7.1
Python 3.12.0
pymongo 4.5.0
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 mongodb/tests/test_mongodb.py 中链接的测试开始,在提供的 GitLab dind job 中复现它;将其行为与 PostgreSQL 测试进行比较。跟踪 MongoDB 容器的暴露端口处理,并在该 pipeline 中重新运行 pytest,且不使用端口映射超时,以验证修复。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- docker, gitlab, mongodb, python
- 领域
- databases, devops, testing
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100