testcontainers-python icon indicating copy to clipboard operation
testcontainers-python copied to clipboard

mongodb testcontainers cannot run in GitLab - while postgres can

Open simcax opened this issue 2 years ago • 1 comments

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

simcax avatar Oct 13 '23 20:10 simcax

https://github.com/testcontainers/testcontainers-python/issues/401

I was having issue with mongo this may help

currently writing as test to support the bug I raised

covatic-john avatar Feb 14 '24 09:02 covatic-john