python - Mongodb gitlab CI docker连接被拒绝
问题描述
我正在尝试为我们的开源爱好项目创建一个 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
此外,项目具有 Angular 前端可能很重要,一旦我们进行了第一次 Angular 测试,它将被添加到测试环境中。
Python 数据库配置:
MONGODB_SETTINGS = {
'host': 'mongodb://127.0.0.1:27017/projekt_eszkozok'
}
还尝试过:
MONGODB_SETTINGS = {
'host': 'mongodb://mongo:27017/projekt_eszkozok'
}
解决方案
正如 yippie-flu 和 Vishesh Kumar Singh 在MongoDB server doesn't start at gitlab runner using gitlab-ci 中localhost:27017
回答的那样,您必须使用 gitlab-ci而不是,mongo:27017
因为 mongo 服务在其自己的 Docker 容器中运行。
推荐阅读
- php - Symfony4:收到邮件的解码过程不起作用
- asp.net-core - 主服务器与一组从服务器合作。最佳实践
- java - 在没有 Swing UI 的情况下如何启动引擎来解决我的问题?
- date - 使用带格式的 day()-formula 时错误的日期 - PowerBI
- angular - 使用 Angular 路由器的模块延迟加载
- ruby-on-rails - 如何从rails中的国家下拉列表中将美国列为首选?
- javascript - 重构嵌套循环以获得更好的性能
- java - 从 Java 调用 Kotlin 伴侣 null
- html - Shopify Curreny Switcher 将重定向到另一个商店 url
- groovy - 更新 cucumber-groovy 后,我得到“对'PickleStepTestStep'的访问超出其访问权限”