Issue connecting to mongo service in Gitlab ci

I am setting up a GitLab pipeline for running test. The test are supposed to use MongoDB, so I want to use the GitLab mongo service. This is my .gitlab-ci.yml:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>image: node:18.19-bullseye
services:
- name: mongo:latest
cache:
paths:
- node_modules/
- t-lib/node_modules
- t-api/node_modules
- t-client/node_modules
unit-tests:
script:
- cd t-api
- npm install
- node ./test-db.js
</code>
<code>image: node:18.19-bullseye services: - name: mongo:latest cache: paths: - node_modules/ - t-lib/node_modules - t-api/node_modules - t-client/node_modules unit-tests: script: - cd t-api - npm install - node ./test-db.js </code>
image: node:18.19-bullseye

services:
  - name: mongo:latest

cache:
  paths:
    - node_modules/
    - t-lib/node_modules
    - t-api/node_modules
    - t-client/node_modules

unit-tests:
  script:
    - cd t-api
    - npm install
    - node ./test-db.js

and this is the ./test-db.js:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import {MongoClient} from 'mongodb';
const url = `mongodb://mongo:27017`;
MongoClient.connect(url, function (err, client) {
if (err) {
console.error(err);
return;
}
console.log("Connected successfully to server");
client.close();
});
</code>
<code>import {MongoClient} from 'mongodb'; const url = `mongodb://mongo:27017`; MongoClient.connect(url, function (err, client) { if (err) { console.error(err); return; } console.log("Connected successfully to server"); client.close(); }); </code>
import {MongoClient} from 'mongodb';

const url = `mongodb://mongo:27017`;

MongoClient.connect(url, function (err, client) {
    if (err) {
        console.error(err);
        return;
    }
    console.log("Connected successfully to server");
    client.close();
});

And this is the output from the GitLab pipeline:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Running with gitlab-runner 17.0.0~pre.88.g761ae5dd (761ae5dd)
on green-6.saas-linux-small-amd64.runners-manager.gitlab.com/default YKxHNyexq, system ID: s_a201ab37b78a
Preparing the "docker+machine" executor
00:37
Using Docker executor with image node:18.19-bullseye ...
Starting service mongo:latest ...
Pulling docker image mongo:latest ...
Using docker image sha256:a31b196b207d768e78f2af331869e91d13443f691080d3b93e8009a53391eeaa for mongo:latest with digest mongo@sha256:54996a559c724c726a31fb8131e1c9088a05f7e531760e2897212389bbf20fed ...
Waiting for services to be up and running (timeout 30 seconds)...
Pulling docker image node:18.19-bullseye ...
Using docker image sha256:01f146fd9fbc62c824fee6dc213dc42bd955b4cb2d6266a4d86e6f3b82930e24 for node:18.19-bullseye with digest node@sha256:ba50a7e017c566a0d6a5af7008f3f4e61cc5a4114f441e5e486b592d1c361567 ...
Preparing environment
00:05
Running on runner-ykxhnyexq-project-37348985-concurrent-0 via runner-ykxhnyexq-s-l-s-amd64-1722786860-9ab4b67c...
Getting source from Git repository
00:01
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/toxicstartup/toxic/.git/
Created fresh repository.
Checking out b4387de2 as detached HEAD (ref is small-improvements)...
Skipping Git submodules setup
$ git remote set-url origin "${CI_REPOSITORY_URL}"
Restoring cache
00:01
Checking cache for default-non_protected...
WARNING: file does not exist
Failed to extract cache
Executing "step_script" stage of the job script
00:53
Using docker image sha256:01f146fd9fbc62c824fee6dc213dc42bd955b4cb2d6266a4d86e6f3b82930e24 for node:18.19-bullseye with digest node@sha256:ba50a7e017c566a0d6a5af7008f3f4e61cc5a4114f441e5e486b592d1c361567 ...
$ cd t-api
$ npm install
added 749 packages, and audited 751 packages in 22s
81 packages are looking for funding
run `npm fund` for details
5 high severity vulnerabilities
To address all issues, run:
npm audit fix
Run `npm audit` for details.
$ node ./test-db.js
/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/sdam/topology.js:278
const timeoutError = new error_1.MongoServerSelectionError(`Server selection timed out after ${serverSelectionTimeoutMS} ms`, this.description);
^
MongoServerSelectionError: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017
at Timeout._onTimeout (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/sdam/topology.js:278:38)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
'mongo:27017' => ServerDescription {
address: 'mongo:27017',
type: 'Unknown',
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 318481,
lastWriteDate: 0,
error: MongoNetworkError: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017
at connectionFailureError (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/cmap/connect.js:367:20)
at Socket.<anonymous> (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/cmap/connect.js:290:22)
at Object.onceWrapper (node:events:632:26)
at Socket.emit (node:events:517:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
cause: Error: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: 'fd76:5338:4685:1:0:242:ac11:3',
port: 27017
},
[Symbol(errorLabels)]: Set(1) { 'ResetPool' }
},
topologyVersion: null,
setName: null,
setVersion: null,
electionId: null,
logicalSessionTimeoutMinutes: null,
primary: null,
me: null,
'$clusterTime': null
}
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined,
[Symbol(errorLabels)]: Set(0) {}
}
Node.js v18.19.1
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
</code>
<code>Running with gitlab-runner 17.0.0~pre.88.g761ae5dd (761ae5dd) on green-6.saas-linux-small-amd64.runners-manager.gitlab.com/default YKxHNyexq, system ID: s_a201ab37b78a Preparing the "docker+machine" executor 00:37 Using Docker executor with image node:18.19-bullseye ... Starting service mongo:latest ... Pulling docker image mongo:latest ... Using docker image sha256:a31b196b207d768e78f2af331869e91d13443f691080d3b93e8009a53391eeaa for mongo:latest with digest mongo@sha256:54996a559c724c726a31fb8131e1c9088a05f7e531760e2897212389bbf20fed ... Waiting for services to be up and running (timeout 30 seconds)... Pulling docker image node:18.19-bullseye ... Using docker image sha256:01f146fd9fbc62c824fee6dc213dc42bd955b4cb2d6266a4d86e6f3b82930e24 for node:18.19-bullseye with digest node@sha256:ba50a7e017c566a0d6a5af7008f3f4e61cc5a4114f441e5e486b592d1c361567 ... Preparing environment 00:05 Running on runner-ykxhnyexq-project-37348985-concurrent-0 via runner-ykxhnyexq-s-l-s-amd64-1722786860-9ab4b67c... Getting source from Git repository 00:01 Fetching changes with git depth set to 20... Initialized empty Git repository in /builds/toxicstartup/toxic/.git/ Created fresh repository. Checking out b4387de2 as detached HEAD (ref is small-improvements)... Skipping Git submodules setup $ git remote set-url origin "${CI_REPOSITORY_URL}" Restoring cache 00:01 Checking cache for default-non_protected... WARNING: file does not exist Failed to extract cache Executing "step_script" stage of the job script 00:53 Using docker image sha256:01f146fd9fbc62c824fee6dc213dc42bd955b4cb2d6266a4d86e6f3b82930e24 for node:18.19-bullseye with digest node@sha256:ba50a7e017c566a0d6a5af7008f3f4e61cc5a4114f441e5e486b592d1c361567 ... $ cd t-api $ npm install added 749 packages, and audited 751 packages in 22s 81 packages are looking for funding run `npm fund` for details 5 high severity vulnerabilities To address all issues, run: npm audit fix Run `npm audit` for details. $ node ./test-db.js /builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/sdam/topology.js:278 const timeoutError = new error_1.MongoServerSelectionError(`Server selection timed out after ${serverSelectionTimeoutMS} ms`, this.description); ^ MongoServerSelectionError: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017 at Timeout._onTimeout (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/sdam/topology.js:278:38) at listOnTimeout (node:internal/timers:569:17) at process.processTimers (node:internal/timers:512:7) { reason: TopologyDescription { type: 'Unknown', servers: Map(1) { 'mongo:27017' => ServerDescription { address: 'mongo:27017', type: 'Unknown', hosts: [], passives: [], arbiters: [], tags: {}, minWireVersion: 0, maxWireVersion: 0, roundTripTime: -1, lastUpdateTime: 318481, lastWriteDate: 0, error: MongoNetworkError: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017 at connectionFailureError (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/cmap/connect.js:367:20) at Socket.<anonymous> (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/cmap/connect.js:290:22) at Object.onceWrapper (node:events:632:26) at Socket.emit (node:events:517:28) at emitErrorNT (node:internal/streams/destroy:151:8) at emitErrorCloseNT (node:internal/streams/destroy:116:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { cause: Error: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) { errno: -111, code: 'ECONNREFUSED', syscall: 'connect', address: 'fd76:5338:4685:1:0:242:ac11:3', port: 27017 }, [Symbol(errorLabels)]: Set(1) { 'ResetPool' } }, topologyVersion: null, setName: null, setVersion: null, electionId: null, logicalSessionTimeoutMinutes: null, primary: null, me: null, '$clusterTime': null } }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, setName: null, maxElectionId: null, maxSetVersion: null, commonWireVersion: 0, logicalSessionTimeoutMinutes: null }, code: undefined, [Symbol(errorLabels)]: Set(0) {} } Node.js v18.19.1 Cleaning up project directory and file based variables 00:01 ERROR: Job failed: exit code 1 </code>
Running with gitlab-runner 17.0.0~pre.88.g761ae5dd (761ae5dd)
  on green-6.saas-linux-small-amd64.runners-manager.gitlab.com/default YKxHNyexq, system ID: s_a201ab37b78a
Preparing the "docker+machine" executor
00:37
Using Docker executor with image node:18.19-bullseye ...
Starting service mongo:latest ...
Pulling docker image mongo:latest ...
Using docker image sha256:a31b196b207d768e78f2af331869e91d13443f691080d3b93e8009a53391eeaa for mongo:latest with digest mongo@sha256:54996a559c724c726a31fb8131e1c9088a05f7e531760e2897212389bbf20fed ...
Waiting for services to be up and running (timeout 30 seconds)...
Pulling docker image node:18.19-bullseye ...
Using docker image sha256:01f146fd9fbc62c824fee6dc213dc42bd955b4cb2d6266a4d86e6f3b82930e24 for node:18.19-bullseye with digest node@sha256:ba50a7e017c566a0d6a5af7008f3f4e61cc5a4114f441e5e486b592d1c361567 ...
Preparing environment
00:05
Running on runner-ykxhnyexq-project-37348985-concurrent-0 via runner-ykxhnyexq-s-l-s-amd64-1722786860-9ab4b67c...
Getting source from Git repository
00:01
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/toxicstartup/toxic/.git/
Created fresh repository.
Checking out b4387de2 as detached HEAD (ref is small-improvements)...
Skipping Git submodules setup
$ git remote set-url origin "${CI_REPOSITORY_URL}"
Restoring cache
00:01
Checking cache for default-non_protected...
WARNING: file does not exist                       
Failed to extract cache
Executing "step_script" stage of the job script
00:53
Using docker image sha256:01f146fd9fbc62c824fee6dc213dc42bd955b4cb2d6266a4d86e6f3b82930e24 for node:18.19-bullseye with digest node@sha256:ba50a7e017c566a0d6a5af7008f3f4e61cc5a4114f441e5e486b592d1c361567 ...
$ cd t-api
$ npm install
added 749 packages, and audited 751 packages in 22s
81 packages are looking for funding
  run `npm fund` for details
5 high severity vulnerabilities
To address all issues, run:
  npm audit fix
Run `npm audit` for details.
$ node ./test-db.js
/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/sdam/topology.js:278
                const timeoutError = new error_1.MongoServerSelectionError(`Server selection timed out after ${serverSelectionTimeoutMS} ms`, this.description);
                                     ^
MongoServerSelectionError: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017
    at Timeout._onTimeout (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/sdam/topology.js:278:38)
    at listOnTimeout (node:internal/timers:569:17)
    at process.processTimers (node:internal/timers:512:7) {
  reason: TopologyDescription {
    type: 'Unknown',
    servers: Map(1) {
      'mongo:27017' => ServerDescription {
        address: 'mongo:27017',
        type: 'Unknown',
        hosts: [],
        passives: [],
        arbiters: [],
        tags: {},
        minWireVersion: 0,
        maxWireVersion: 0,
        roundTripTime: -1,
        lastUpdateTime: 318481,
        lastWriteDate: 0,
        error: MongoNetworkError: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017
            at connectionFailureError (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/cmap/connect.js:367:20)
            at Socket.<anonymous> (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/cmap/connect.js:290:22)
            at Object.onceWrapper (node:events:632:26)
            at Socket.emit (node:events:517:28)
            at emitErrorNT (node:internal/streams/destroy:151:8)
            at emitErrorCloseNT (node:internal/streams/destroy:116:3)
            at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
          cause: Error: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017
              at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
            errno: -111,
            code: 'ECONNREFUSED',
            syscall: 'connect',
            address: 'fd76:5338:4685:1:0:242:ac11:3',
            port: 27017
          },
          [Symbol(errorLabels)]: Set(1) { 'ResetPool' }
        },
        topologyVersion: null,
        setName: null,
        setVersion: null,
        electionId: null,
        logicalSessionTimeoutMinutes: null,
        primary: null,
        me: null,
        '$clusterTime': null
      }
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: null,
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined,
  [Symbol(errorLabels)]: Set(0) {}
}
Node.js v18.19.1
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

Seems like the alias mongo has been replaced by IPv6 (which I assume means the service has started successfully), but the connection does not work. Any ideas how to make this work?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật