Редис собирается:
FROM redis
COPY redis.conf /usr/local/etc/redis/redis.conf
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
И запускается в составе других сервисов через компоуз:
volumes:
db_data:
name: dship-data
obj_storage:
name: dship-minio
services:
site:
image: node:17.9-alpine3.14
container_name: dship-site-dev
expose: [3000]
ports:
- 3000:3000
volumes:
- type: bind
source: /home/nodejs/dship
target: /home/nodejs/dship
working_dir: /home/nodejs/dship
command: node main.js
depends_on:
- redis
redis:
build: ./_docker/redis
container_name: dship-redis
expose: [6377]
ports:
- 6379:6379
tmpfs:
- /data:size=52428800 # 50Mb
Лог при запуске:
dship-redis | 1:C 24 Apr 2022 21:47:05.704 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
dship-redis | 1:C 24 Apr 2022 21:47:05.704 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=1, just started
dship-redis | 1:C 24 Apr 2022 21:47:05.704 # Configuration loaded
dship-redis | 1:M 24 Apr 2022 21:47:05.706 * monotonic clock: POSIX clock_gettime
dship-redis | 1:M 24 Apr 2022 21:47:05.728 * Running mode=standalone, port=6379.
dship-redis | 1:M 24 Apr 2022 21:47:05.729 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
dship-redis | 1:M 24 Apr 2022 21:47:05.729 # Server initialized
dship-redis | 1:M 24 Apr 2022 21:47:05.729 * Ready to accept connections
Тестовое обращение из ноды:
export class RedisDriver {
constructor(config) {
this.client = createClient(config);
this.client.on('error', err => console.log('Redis Client Error -> ', err));
}
async _connect() {
try {
console.log('----2');
await this.client.connect();
} catch (err) {
throw new Error(`${this.constructor.name} -> _connect() -> ${err.message}`);
}
}
async test() {
try {
console.log('----1');
if (!this.client.isOpen) await this._connect();
console.log('----3');
const info = await this.client.info();
console.log('Redis test: ', info);
} catch (err) {
throw new Error(`${this.constructor.name} -> test() -> ${err.message}`);
}
}
}
Конфиг, который передается в конструктор экзеспляра клиента:
{
host: '127.0.0.1',
port: 6379,
}
(Пробовал так же поставить host: 'redis' и даже * -::*)
Получаю ошибку на этапе await this._connect():
dship-site-dev | Redis Client Error -> Error: connect ECONNREFUSED 127.0.0.1:6379
dship-site-dev | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16) {
dship-site-dev | errno: -111,
dship-site-dev | code: 'ECONNREFUSED',
dship-site-dev | syscall: 'connect',
dship-site-dev | address: '127.0.0.1',
dship-site-dev | port: 6379
dship-site-dev | }
При таком конфиге редиса:
# Allow connections from all peers
# bind * -::*
bind 127.0.0.1
# Close the connection after a client is idle for N seconds (0 to disable)
timeout 0
# Only one dtatbase per container
databases 1
maxclients 10000
# Shoulf be corresponding with compose.yaml
maxmemory 50mb
# SNAPSHOTS ############################################
# Save to disk after 5 minutes if at least 1 key changed
save 300 1
# Do not continue written if disk problem
stop-writes-on-bgsave-error yes
# Compress dump file
rdbcompression yes
# It cost around 10%
rdbchecksum yes
# dir for dump file
dir ./
dbfilename dump.rdb
В bind так же пробовал прописать имя сервиса (redis). Не помогло.
Использую сеть Докера по умолчанию:
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
В чем может быть проблема?