testcontainers / testcontainers/testcontainers-python

mongodb testcontainers cannot run in GitLab - while postgres can

Open
#386 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🐛 bug 📦 package: mongodb 🔀 requires triage
Dominant language
Python
Stars
2.3k
Forks
386
Avg merge
4h 40m
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with mongodb/tests/test_mongodb.py at the linked test and reproduce it in the supplied GitLab dind job; compare its behavior with the PostgreSQL test. Trace the MongoDB container's exposed-port handling and verify the fix by rerunning pytest in that pipeline without the port-mapping timeout.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, gitlab, mongodb, python
Domain
databases, devops, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.