这可能只是一般的 WSL 相关,但 Redis 是我的用例。
这很好用,我可以像这样连接:
docker exec -it redis-1 redis-cli -c -p 7001 -a Password123
但是我无法从我的本地 Windows pc 到容器建立任何连接。我得到
<块引用>无法连接:连接到 host.docker.internal:7001 时出现错误 10061。由于目标机器主动拒绝,无法建立连接。
当容器没有运行时,这也是同样的错误,所以不确定是 docker 问题还是 WSL?
version: '3.9'
services:
redis-cluster:
image: redis:latest
container_name: redis-cluster
command: redis-cli -a Password123 -p 7001 --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluster-replicas 1 --cluster-yes
depends_on:
- redis-1
- redis-2
- redis-3
- redis-4
- redis-5
- redis-6
network_mode: host
redis-1:
image: "redis:latest"
container_name: redis-1
network_mode: host
entrypoint: >
redis-server
--port 7001
--appendonly yes
--cluster-enabled yes
--cluster-config-file nodes.conf
--cluster-node-timeout 5000
--masterauth Password123
--requirepass Password123
--bind 0.0.0.0
--protected-mode no
# Five more the same as the above