我想将我的nodejs
应用程序连接到arangodb
. 我正在使用arangojs
这个。我的连接代码看起来像
new Database({
url: `${DB_URL}:${DB_PORT}`,
auth: {
username: DB_USERNAME,
password: DB_PASSWORD
}
})
Error: connect EINVAL 0.0.33.81:80 - Local (0.0.0.0:0)
nodeserver_1 | at internalConnect (node:net:905:16)
nodeserver_1 | at defaultTriggerAsyncIdScope (node:internal/async_hooks:431:18)
nodeserver_1 | at GetAddrInfoReqWrap.emitLookup [as callback] (node:net:1051:9)
nodeserver_1 | at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:8) {
nodeserver_1 | errno: -22,
nodeserver_1 | code: 'EINVAL',
nodeserver_1 | syscall: 'connect',
nodeserver_1 | address: '0.0.33.81',
nodeserver_1 | port: 80,
尽管
DB_URL=db
DB_PORT=8529
我的 docker-compose.yml 看起来像这样:
version: '3.9'
services:
db:
image: arangodb:latest
environment:
ARANGO_ROOT_PASSWORD: ${DB_PASSWORD:-root}
ports:
- ${DB_PORT:-8529}:8529
volumes:
- arangodb_data_container:/var/lib/arangodb3
- arangodb_apps_data_container:/var/lib/arangodb3-apps
network_mode: bridge
nodeserver:
build:
context: .
depends_on:
- db
environment:
DB_PORT: ${DB_PORT}
DB_NAME: ${DB_NAME}
DB_USERNAME: ${DB_USERNAME}
DB_PASSWORD: ${DB_PASSWORD}
DB_URL: ${DB_URL}
restart: unless-stopped
network_mode: bridge
volumes:
arangodb_data_container:
arangodb_apps_data_container:
知道我做错了什么吗?
编辑:我检查了容器 IP 地址,但与我预期的不一样:
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' 4059b252e72e
172.17.0.2
Edit2:我误解了错误。原因是以下代码:
let db = new Database({
url: `${DB_URL}:${DB_PORT}`,
auth: {
username: DB_USERNAME,
password: DB_PASSWORD,
}
db = db.database(DB_NAME)
const databaseExists = await DB.database.exists() // here the error gets thrown