简体   繁体   中英

Mongodb gitlab CI docker connection refused

I am trying to create a docker test enviroment for our opensource hobby project. Our python and angular code is running without errors. I need a little help with configuring the docker runner to include 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/"

The error:

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

Also it might matter that the project have Angular frontend which is going to be added to the test enviroment once we made our first Angular test.

Python database config:

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

Also tried with:

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

As yippie-flu and Vishesh Kumar Singh answered in MongoDB server doesn't start at gitlab runner using gitlab-ci , instead of localhost:27017 , you have to use mongo:27017 because the mongo service is running in its own Docker container.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM