Mongodb gitlab CI docker连接被拒绝

2024-10-01 17:41:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图为我们的开源爱好项目创建一个docker测试环境。我们的python和angular代码运行时没有错误。我需要一些帮助来配置docker runner以包括mongodb

stages: 
- build
- test

services:
  - mongo

variables:
  MONGODB_URI: "mongodb://mongo/projekt_eszkozok"


build: 
  stage: build
  image: "python:3.8.2"
  script:
    - "pip3 install -r sources/backend/requirements.txt"

test:
  stage: test
  image: "python:3.8.2"
  script:
    - "pip3 install -r sources/backend/requirements.txt"
    - cd sources/backend
    - "python -m unittest discover tests/"

错误:

pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused

此外,项目具有角度前端也可能很重要,一旦我们进行了第一次角度测试,它将被添加到测试环境中

Python数据库配置:

MONGODB_SETTINGS = {
    'host': 'mongodb://127.0.0.1:27017/projekt_eszkozok'
}

还尝试了:

MONGODB_SETTINGS = {
    'host': 'mongodb://mongo:27017/projekt_eszkozok'
}

Tags: 项目dockertestimagebuildbackend测试环境mongo

热门问题